【发布时间】:2011-08-29 10:30:39
【问题描述】:
我想在一个 twig 块中生成表头并在整个页面中重复使用它们,这个页面有大约 5 个不同的表,它们的表头大致相同。块代码是这样的:
{% block table_headers %}
<th>Fiscal Year</th>
<th>End Date</th>
<th>Period Length</th>
{% for item in result.FinancialStatements.COAMap.mapItem %}
{% if item.statementType == statementType %}
<th>{{ item._ }} ({{ item.coaItem }})</th>
{% endif %}
{% endfor %}
{% endblock %}
上面代码中的关键行是
{% if item.statementType == statementType %}
我想将 statementType 作为参数传递给我渲染块的位置,如下所示:
{% render block.table_headers with {'statementType': 'INC'} %}
但这不起作用。为了概念上的接近,我想将块及其渲染保留在同一个文件(但不同的块)中。
甚至可以使用这样的块吗?我查看了 Symfony2 文档,找不到任何建议可以这样做的信息,但对我来说,这似乎是对块的明显使用。
【问题讨论】: