I'm doing a project in symfony and I would like to load a template with the use statement.
This is what I like to do:
{% for p in db.page. %}
{% use 'PageBundle:Pages:' ~ p.template ~ '.html.twig' %}
{% endfor %}
But don't allow it. Returns the following error message:
The template references in a "use" statement must be a string
Can anyone help?
Thanks!
Twig's use function cannot being called using dynamic variables or expressions like OP.
Twig Documentation says: Because use statements are resolved independently of the context passed tothe template, the template reference cannot be an expression.
Refer to this link for more info: Twig Issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With