我是Twig的新手。有没有类似Jade的带有嵌套块的mixins?我的意思是这样的:
mixin button(text)
.btn
.txt= text
.dropdown
block
+button("button")
+button("sub1")
+button("sub1-1")
+button("sub1-2")
+button("sub2")
+button("sub2-1")
.custom1 blah-blah
+button("sub3")
+button("sub3-1")
+button("sub3-2")发布于 2015-12-06 15:37:34
我找到了某种解决方案。我刚刚将宏拆分成2+宏。
{% __btns.twig %}
{% macro btn1_opening(text) %}
<div class="button1">
<div class="text">{{ text }}</div>
<div class="dropdown">
{% endmacro %}
{% macro btn1_closing() %}
</div>
</div>
{% endmacro %}
{# main.twig #}
{% import "__btns.twig" as btns %}
{{ btns.btn1_opening("I am button") }}
<div class="something-inside-dropdown">
{% include "somefile.twig" %}
</div>
{{ btns.btn1_closing() }}因此,在这种情况下,即使我需要在宏中包含多个块,我也可以在开始、中间和结束宏之间编写一些HTML。
https://stackoverflow.com/questions/34100468
复制相似问题