2
因此,我在nunjucks中遇到了一個奇特的事情,我真的需要修復它。包含的nunjucks文件中的循環索引
想象我有即index.nj
{% for item in items %}
{% include "/file2.nj" %}
{% endfor %}
現在一個循環,file2.nj我想如下處理循環索引:
{{ loop.index }}
這沒有按」 t工作的原因,但奇怪的是,如果我第一次添加loop.index在index.nj文件,它的確如此。
即
{% for item in items %}
{{loop.index}}
{% include "/file2.nj" %}
{% endfor %}
在上面的例子,file2.nj可以調用loop.index本身。 爲什麼它不知道loop.index,但是當我把它稱爲upfront(這也可以在,如果什麼都不做,我測試過),該文件有權訪問它?
如果有人知道如何解決這個問題,我會很高興。
,也許你可以使用宏和傳遞迴路。索引能夠訪問它? – Stephen