如何停止具有“包含标签”的循环。在nunjucks中的某些项目中?
我在我的博客网站上有此代码,但我希望循环停止,例如第二个项目/文章或第三个
<div class="container mar2ritlft">
<div class="content3col">
{%- for article in collections.article | reverse -%}
{% include 'article-post.njk' %}
{%- endfor -%}
</div>
</div>
PS:“ collections.tricle”是元数据中具有“文章”标签的博客
I have this code on my blog site but I want the loop to stop in, for example, the second item/article or third
<div class="container mar2ritlft">
<div class="content3col">
{%- for article in collections.article | reverse -%}
{% include 'article-post.njk' %}
{%- endfor -%}
</div>
</div>
Ps: the "collections.article" is blogs that have "article" tag in the metaData
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要通过允许循环的索引与实际文章有关系,重新考虑通过多个文章循环的方法。 是这样,您应该能够完成以下内容...
,您将拥有类似的东西。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
...ETC...
You may want to reconsider your approach on looping through multiple articles by allowing the index of your loop to have a relationship to the actual articles. If so, you should be able to pull off the following...
In your articles/ directory, you would have something like...
...etc...