1

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
Tuan nguyen
  • 560
  • 6
  • 19

1 Answers1

1

Try template_from_string function.

{{ include(template_from_string("Hello {{ name }}") }}
Alexey B.
  • 11,965
  • 2
  • 49
  • 73