Class yii\twig\html\CssClassNode
| Inheritance | yii\ |
|---|---|
| Source Code | https://github.com/yiisoft/yii2-twig/blob/master/html/CssClassNode.php |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | yii\ |
|
| compile() | yii\ |
|
| getHelperMethod() | yii\ |
Method Details
| public __construct( \Twig\Token $name, mixed $value, \Twig\Token $operator, mixed $lineno = 0, string|null $tag = null ): mixed | ||
| $name | \Twig\Token | |
| $value | mixed | |
| $operator | \Twig\Token | |
| $lineno | mixed | |
| $tag | string|null | |
public function __construct(Token $name, $value, Token $operator, $lineno = 0, ?string $tag = null)
{
parent::__construct(['value' => $value], ['name' => $name, 'operator' => $operator], $lineno, $tag);
}
Defined in:
yii\
| public compile( \Twig\Compiler $compiler ): mixed | ||
| $compiler | \Twig\Compiler | |
public function compile(Compiler $compiler)
{
$name = $this->getAttribute('name')->getValue();
$method = $this->getHelperMethod();
$compiler
->addDebugInfo($this)
->write("\yii\helpers\Html::{$method}(\$context[\"{$name}\"],")
->subcompile($this->getNode('value'))
->raw(");\n");
}
| public getHelperMethod( ): mixed |
public function getHelperMethod()
{
$operator = $this->getAttribute('operator')->getValue();
switch ($operator) {
case '+':
return 'addCssClass';
case '-':
return 'removeCssClass';
default:
throw new Error("Operator {$operator} no found;");
}
}