我需要做一個循環與包含在樹枝中的指令,但模板樹枝不會重複。這是我的代碼片段:對於在樹枝與包括
...
{% for object in objects %}
{% include 'template.html.twig' with {'object':object} %}
{% endfor %}
...
只收到第一個對象,但是我需要的其餘對象沒有收到。
我需要做一個循環與包含在樹枝中的指令,但模板樹枝不會重複。這是我的代碼片段:對於在樹枝與包括
...
{% for object in objects %}
{% include 'template.html.twig' with {'object':object} %}
{% endfor %}
...
只收到第一個對象,但是我需要的其餘對象沒有收到。
該問題與TWIG無關,錯誤出現在JQUERY中。 FOR-LOOP在包含INCLUDE的情況下有效。
模板嫩枝1:打印n,其中不同的內容
模態...
{% for object in objects %}
{% include 'template2.html.twig' with {'object':object} %}
<button type="button" class="btn-primary" title="modal-view" data-toggle="modal" data-target="#modal-{{object['id_object']}}">View</button>
{% endfor %}
...
模板嫩枝2:模式引導
...
<div id="modal-{{object['id_object']}}" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title">{{object['title']}}</h2>
</div>
<div class="modal-body">
<p>{{object['content']}}</p>
</div>
</div>
</div>
</div>
...
我沒有嘗試過這樣的事情之前,但我不知道這可能會奏效與否:
{% include 'template.html.twig' with {'objects':objects} %}
爲了話不把在for循環,並將其直接傳遞objects
您包含模板,然後在template.html.twig
中也可以直接使用objects
數組。
再一次,我不確定這是否可行;也許你可以嘗試一下,或者你需要一些不同的東西。
感謝,在這種情況下,如果它的工作原理,但我不得不走再次矩陣。在樹枝模板中,我設計了一個模式,但它的變化像對象的名稱和對象的描述。 – Dasaaf
您需要包含相關代碼才能給我們一個很好的答案。很高興你的工作雖然。 –