Nunjucks for 循环 运行 两次
Nunjucks for loop running twice
我正在使用 Nunjucks 和 Eleventy 构建网站。我正在尝试使用 Nunjucks for 循环创建一个无序列表(数据存储在 JSON 文件中)。一切似乎都在工作,除了循环 运行 两次,而它应该只 运行 一次。
JSON
{"catalog":[
{"title":"Title #1","author":"Author #1","edition":"Third","isbn":"19384579823745","available":"0","total":"4"},
{"title":"Title #2","author":"Author #2","edition":"Fifth","isbn":"1390458093484","available":"2","total":"2"},
{"title":"Title #3","author":"Author #3","edition":"First","isbn":"8974692873489","available":"1","total":"3"},
{"title":"Title #4","author":"Author #4","edition":"Third","isbn":"19384579823745","available":"0","total":"4"},
{"title":"Title #5","author":"Author #5","edition":"Fifth","isbn":"19384579823745","available":"0","total":"4"},
{"title":"Title #6","author":"Author #6","edition":"First","isbn":"1390458093484","available":"2","total":"2"},
{"title":"Title #7","author":"Author #7","edition":"First","isbn":"19384579823745","available":"0","total":"4"},
{"title":"Title #8","author":"Author #8","edition":"First","isbn":"1390458093484","available":"2","total":"2"},
{"title":"Title #9","author":"Author #9","edition":"Second","isbn":"19384579823745","available":"0","total":"4"},
{"title":"Title #10","author":"Author #10","edition":"Second","isbn":"1390458093484","available":"2","total":"2"},
{"title":"Title #11","author":"Author #11","edition":"Second","isbn":"8974692873489","available":"1","total":"3"}
]}
Nunjucks
{% if sheet.catalog %}
<ul class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4">
{% for textbook in sheet.catalog %}
<li class="m-10"><strong>{{ textbook.title }}</strong><br />{{ textbook.author }}<br />Edition: {{ textbook.edition }}<br />ISBN: {{ textbook.isbn }}<br />Available: {{ textbook.available }} of {{ textbook.total }}</li>
{% endfor %}
</ul>
{% else %}
<p>We're sorry. The textbook catalog has encountered an error.</p>
{% endif %}
HTML输出
<ul class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4">
<li class="m-10"><strong>Title #1</strong><br>Author #1<br>Edition: Third<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #2</strong><br>Author #2<br>Edition: Fifth<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #3</strong><br>Author #3<br>Edition: First<br>ISBN: 8974692873489<br>Available: 1 of 3</li>
<li class="m-10"><strong>Title #4</strong><br>Author #4<br>Edition: Third<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #5</strong><br>Author #5<br>Edition: Fifth<br>ISBN: 19384579823745<br>Available: 0 of 4</li><li class="m-10"><strong>Title #6</strong><br>Author #6<br>Edition: First<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #7</strong><br>Author #7<br>Edition: First<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #8</strong><br>Author #8<br>Edition: First<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #9</strong><br>Author #9<br>Edition: Second<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #10</strong><br>Author #10<br>Edition: Second<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #11</strong><br>Author #11<br>Edition: Second<br>ISBN: 8974692873489<br>Available: 1 of 3</li>
<li class="m-10"><strong>Title #1</strong><br>Author #1<br>Edition: Third<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #2</strong><br>Author #2<br>Edition: Fifth<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #3</strong><br>Author #3<br>Edition: First<br>ISBN: 8974692873489<br>Available: 1 of 3</li>
<li class="m-10"><strong>Title #4</strong><br>Author #4<br>Edition: Third<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #5</strong><br>Author #5<br>Edition: Fifth<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #6</strong><br>Author #6<br>Edition: First<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #7</strong><br>Author #7<br>Edition: First<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #8</strong><br>Author #8<br>Edition: First<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #9</strong><br>Author #9<br>Edition: Second<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #10</strong><br>Author #10<br>Edition: Second<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #11</strong><br>Author #11<br>Edition: Second<br>ISBN: 8974692873489<br>Available: 1 of 3</li>
</ul>
知道为什么 for 循环 运行ning 两次吗?非常感谢您的帮助!
我的输入文件夹中保存了 JSON 文件的副本。我删除了它,现在 HTML 输出不再额外显示渲染数据。谢谢@RaymondCamden!
我正在使用 Nunjucks 和 Eleventy 构建网站。我正在尝试使用 Nunjucks for 循环创建一个无序列表(数据存储在 JSON 文件中)。一切似乎都在工作,除了循环 运行 两次,而它应该只 运行 一次。
JSON
{"catalog":[
{"title":"Title #1","author":"Author #1","edition":"Third","isbn":"19384579823745","available":"0","total":"4"},
{"title":"Title #2","author":"Author #2","edition":"Fifth","isbn":"1390458093484","available":"2","total":"2"},
{"title":"Title #3","author":"Author #3","edition":"First","isbn":"8974692873489","available":"1","total":"3"},
{"title":"Title #4","author":"Author #4","edition":"Third","isbn":"19384579823745","available":"0","total":"4"},
{"title":"Title #5","author":"Author #5","edition":"Fifth","isbn":"19384579823745","available":"0","total":"4"},
{"title":"Title #6","author":"Author #6","edition":"First","isbn":"1390458093484","available":"2","total":"2"},
{"title":"Title #7","author":"Author #7","edition":"First","isbn":"19384579823745","available":"0","total":"4"},
{"title":"Title #8","author":"Author #8","edition":"First","isbn":"1390458093484","available":"2","total":"2"},
{"title":"Title #9","author":"Author #9","edition":"Second","isbn":"19384579823745","available":"0","total":"4"},
{"title":"Title #10","author":"Author #10","edition":"Second","isbn":"1390458093484","available":"2","total":"2"},
{"title":"Title #11","author":"Author #11","edition":"Second","isbn":"8974692873489","available":"1","total":"3"}
]}
Nunjucks
{% if sheet.catalog %}
<ul class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4">
{% for textbook in sheet.catalog %}
<li class="m-10"><strong>{{ textbook.title }}</strong><br />{{ textbook.author }}<br />Edition: {{ textbook.edition }}<br />ISBN: {{ textbook.isbn }}<br />Available: {{ textbook.available }} of {{ textbook.total }}</li>
{% endfor %}
</ul>
{% else %}
<p>We're sorry. The textbook catalog has encountered an error.</p>
{% endif %}
HTML输出
<ul class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4">
<li class="m-10"><strong>Title #1</strong><br>Author #1<br>Edition: Third<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #2</strong><br>Author #2<br>Edition: Fifth<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #3</strong><br>Author #3<br>Edition: First<br>ISBN: 8974692873489<br>Available: 1 of 3</li>
<li class="m-10"><strong>Title #4</strong><br>Author #4<br>Edition: Third<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #5</strong><br>Author #5<br>Edition: Fifth<br>ISBN: 19384579823745<br>Available: 0 of 4</li><li class="m-10"><strong>Title #6</strong><br>Author #6<br>Edition: First<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #7</strong><br>Author #7<br>Edition: First<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #8</strong><br>Author #8<br>Edition: First<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #9</strong><br>Author #9<br>Edition: Second<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #10</strong><br>Author #10<br>Edition: Second<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #11</strong><br>Author #11<br>Edition: Second<br>ISBN: 8974692873489<br>Available: 1 of 3</li>
<li class="m-10"><strong>Title #1</strong><br>Author #1<br>Edition: Third<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #2</strong><br>Author #2<br>Edition: Fifth<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #3</strong><br>Author #3<br>Edition: First<br>ISBN: 8974692873489<br>Available: 1 of 3</li>
<li class="m-10"><strong>Title #4</strong><br>Author #4<br>Edition: Third<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #5</strong><br>Author #5<br>Edition: Fifth<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #6</strong><br>Author #6<br>Edition: First<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #7</strong><br>Author #7<br>Edition: First<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #8</strong><br>Author #8<br>Edition: First<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #9</strong><br>Author #9<br>Edition: Second<br>ISBN: 19384579823745<br>Available: 0 of 4</li>
<li class="m-10"><strong>Title #10</strong><br>Author #10<br>Edition: Second<br>ISBN: 1390458093484<br>Available: 2 of 2</li>
<li class="m-10"><strong>Title #11</strong><br>Author #11<br>Edition: Second<br>ISBN: 8974692873489<br>Available: 1 of 3</li>
</ul>
知道为什么 for 循环 运行ning 两次吗?非常感谢您的帮助!
我的输入文件夹中保存了 JSON 文件的副本。我删除了它,现在 HTML 输出不再额外显示渲染数据。谢谢@RaymondCamden!