Fidel Castro
Fidel Castro

Reputation: 337

How to assign variables in twig?

Im migrating my code from smarty to twig

but I dont seem to find how to do this in twig

smarty:

 $smarty->assign('Config',$Core->settings);

how can I do this in Twig ?

Upvotes: 1

Views: 10665

Answers (1)

Alvin Bunk
Alvin Bunk

Reputation: 7764

You would use 'set'. http://twig.sensiolabs.org/doc/tags/set.html Then you would have to pass in $Core->settings as a variable from your controller like so:

return $this->render('my_template.html.twig', array(
        'core_settings' => $Core->settings,
));

Then in my_template.html.twig you would use set like this:

{% set 'Config' = core_settings %}

I'm not sure if that works for you, Twig is different than smarty (I'm not very familar with smarty) but Twig is powerful.

Upvotes: 8

Related Questions