简体   繁体   中英

Make Twig syntax from string be parsed

I stored a format of shopping order in database, it's like #{{ number }} (it's just a string), how can use this {{ number }} as a execution of Twig.

For example, in my Controller, when I render the view, I also pass a $number variable:

return $this->render('MyBundle:View:index.html.twig', array('number' => 123));

and in my index.html.twig file, it's something like

{% set orderFormat = some_function_to_get_order_format() %} 
// orderFormat will be #{{ number }}
// What can I do to print orderFormat to #123

尝试使用template_from_string函数。

{{ include(template_from_string("Hello {{ name }}") }}

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