P
P
Pavel Inky2015-01-21 11:35:37
Yii
Pavel Inky, 2015-01-21 11:35:37

How to pass variable from Controller to views of TWIG widget?

Hello to all.
Yii, and especially twig, I know very superficially, that's why I ask for your help.
How is it possible, if at all, to pass a variable declared in protected\controllers\ProjectsController.php to pass it to the protected\views\widgets\catalog.twig template
. I have a variable - $new and ProjectsController.php is declared and it would need to be output to the catalog widget template. twig
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Makarov, 2015-02-17
@SamDark

Just like without Twig:

$this->render('viewName', array(
    'new' => $new,
));

F
forweb4, 2016-04-28
@forweb4

It is possible in the controller:
public $var;
public function init()
{
$this->var = 'bla-bla';
}
in view:
<?=$this->context->var; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question