Fidel Castro Fidel Castro - 13 days ago 5
Smarty Question

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 ?

Answer

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.