简体   繁体   中英

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM