是否可以在include标记中使用for循环? {%include./partial/project.twig'和{'status':'pass project', “statusClass”:“过去”, “英雄形象”:“/dist/images/projects/project-south16th.jpg”, “logo”:“/dist/images/logo-south16.png”, ‘描述’:‘23套三床和四床联排别墅’, “地址”:“南萨里16大街15885号”, “展厅”:没错, “galleryID”:“south16th”, “链接”:“链接”, “厨房图像”:“ {范围(1,10)%内的i的百分比} {%endfor%} " } %}
上面的代码无效,因为twig似乎不允许在include标记中嵌套标记?还是我做错了什么 有没有其他方法可以实现这一目标?我想将此代码重复X次并将其传递给模板:是否可以在include标记中使用for循环? {%include./partial/project.twig'和{'status':'pass project', “statusClass”:“过去”, “英雄形象”:“/dist/images/projects/project-south16th.jpg”, “logo”:“/dist/images/logo-south16.png”, ‘描述’:‘23套三床和四床联排别墅’, “地址”:“南萨里16大街15885号”, “展厅”:没错, “galleryID”:“south16th”, “链接”:“链接”, “厨房图像”:“ {范围(1,10)%内的i的百分比} {%endfor%} " } %},twig,Twig,上面的代码无效,因为twig似乎不允许在include标记中嵌套标记?还是我做错了什么 有没有其他方法可以实现这一目标?我想将此代码重复X次并将其传递给模板: {% include './partial/project.twig' with {'status': 'Past Project', 'statusClass': 'past',
{% include './partial/project.twig' with {'status': 'Past Project',
'statusClass': 'past',
'heroImage': "/dist/images/projects/project-south16th.jpg",
'logo': '/dist/images/logo-south16th.png',
'desc': '23 three- and four-bed townhomes',
'address': '15885 16 Avenue, South Surrey',
'showGallery': true,
'galleryID': 'south16th',
'link': '#',
'galleryImages': "
{% for i in range(1, 10) %}
<a data-fancybox='south16th' href='{{ theme.uri }}/dist/images/gallery/south16/{{ i }}.jpg'></a>
{% endfor %}
"
} %}
{i在(1,10)%范围内的百分比}
{%endfor%}
要实现这一点,您需要切换到嵌入
,而不是包含
小枝索引
{%embed'include.twig'和{'theme':{'uri':'https://www.example.com“,”图片“:10,},}%}
{%block pictures%}
{%1..theme.pictures%}
{%endfor%}
{%endblock%}
{%endembed%}
包括小枝
包括
{{theme.uri}}-{{theme.pictures}
{%block pictures%}
{%endblock%}
注意:您将在
中定义的变量包括.twig
也将在嵌入中可用要实现这一点,您需要切换到嵌入
,而不是包含
小枝索引
{%embed'include.twig'和{'theme':{'uri':'https://www.example.com“,”图片“:10,},}%}
{%block pictures%}
{%1..theme.pictures%}
{%endfor%}
{%endblock%}
{%endembed%}
包括小枝
包括
{{theme.uri}}-{{theme.pictures}
{%block pictures%}
{%endblock%}
注意:您将在
中定义的变量包括.twig
也将在嵌入中可用使用“{%set%}”使用“{%set%}”
{% for i in range(1, 10) %}
<a data-fancybox='south16th' href='{{ theme.uri }}/dist/images/gallery/south16/{{ i }}.jpg'></a>
{% endfor %}
{% embed 'include.twig' with { 'theme': { 'uri' : 'https://www.example.com', 'pictures': 10, }, } %}
{% block pictures %}
{% for i in 1..theme.pictures %}
<li><a data-fancybox='south16th' href='{{ theme.uri }}/dist/images/gallery/south16/{{ i }}.jpg'></a></li>
{% endfor %}
{% endblock %}
{% endembed %}
<h1>Include</h1>
<h2>{{ theme.uri }} - {{ theme.pictures }}</h2>
<ul>
{% block pictures %}
{% endblock %}
</ul>