本文介绍了如何多次重用一个块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在树枝模板的视图中多次渲染块?目前我确实有一个块,我们称之为 something
定义在一个包含的(通过 render
)twig 文件中.然后我使用以下命令将其包含在 layout-twig 文件中:
How can I render a block multiple times within a view in a twig template? Currently I do have a block, let's call it something
defined in an included (via render
) twig file. I then include it at the layout-twig file using the following:
{% block something %}{% endblock %}
一切都很好,但是一旦我第二次调用这个标签,我就会收到以下错误消息:
Everything is fine, however as soon as I call this tag a second time, I get the following error message:
The block 'something ' has already been defined in "::layout.html.twig"
因此:如何多次渲染一个块?
Therefore: How can I render a block multiple times?
推荐答案
您向我们展示的符号用于定义和呈现块.仅渲染是这样完成的:
The notation you're showing us is for defining and rendering a block. Rendering only is done this way:
{{ block('blockName') }}
这篇关于如何多次重用一个块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!