2016-12-30 120 views
0

我的樹枝模板具有for循環,並且我正在嘗試向其添加可變長度。我該怎麼做呢?具有變量的樹枝模板

('var')需要是變量>內容。 + var + .related.buttons

{% include '@PleinCatalog/Theme/includes/themeCatergory.html.twig' with {'var':'something'} %} 
{% for button in content.('var').related.buttons %} 
     <a href="{{ button.url }}" class="btn btn-block btn-success">{{ button.title }}</a> 
{% endfor %} 
+1

我認爲它應該像這樣工作'{%,爲內容按鈕[VAR] .related.buttons%}' –

+0

工程就像一個魅力..謝謝! – Christien

回答

2

我在我的項目中有一個類似的循環,其中包括一些選項的模板。

根據你的榜樣 - 它可以是這樣的用途:

{% for button in content[var].related.buttons %} 
    … 
{% endfor %}