根据用户的语言环境包含带有变量的模板
Include template with variable depending on locale of user
我想根据用户的区域设置包含模板。
这是静态代码,它工作正常
{% include 'AppBundle:Frontend:content_en.html.twig' %}
我试过了,但没用:
{% include {{ 'AppBundle:Frontend:content_' ~ app.request.locale ~ '.html.twig' }} %}
这是错误
A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses
(unexpected token "punctuation" of value "{" in AppBundle:Frontend:index.html.twig at line 18
已解决
{{ include ('AppBundle:Frontend:content_' ~ app.request.locale ~ '.html.twig') }}
我想根据用户的区域设置包含模板。 这是静态代码,它工作正常
{% include 'AppBundle:Frontend:content_en.html.twig' %}
我试过了,但没用:
{% include {{ 'AppBundle:Frontend:content_' ~ app.request.locale ~ '.html.twig' }} %}
这是错误
A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses
(unexpected token "punctuation" of value "{" in AppBundle:Frontend:index.html.twig at line 18
已解决
{{ include ('AppBundle:Frontend:content_' ~ app.request.locale ~ '.html.twig') }}