如何定义全局块,然后在树枝内部渲染


How can I define global block then render inside twig?

是否可以为twitch文件设置全局块,以便我可以访问twitch内的块。

例如,我想将{%block currency%}${%endblock%}此块作为全局块,然后我想在所有其他分支中渲染此块,如{{block('currency')}}

您只需要创建包含该块的分支,然后在config.yml 中添加该文件

# app/config/config.yml
twig:
    form_themes:
        - 'form/fields.html.twig'

您可以在烹饪书

中看到一个例子