【问题标题】:Limit amount of articles with a loop使用循环限制文章数量
【发布时间】:2014-09-25 13:38:50
【问题描述】:

在我的索引页面上,我想给出两个单独的文章列表(顺便说一下,我不介意使用分页插件),并且我想列出每个“类别”中的最后 5 个。但我不知道如何在循环中计数。

我已经试过了

#{news-loop} = #{news-loop} + 1

但这没有用。

- var news-loop = 0
block content
  section.work.index
    h2 Arbeiten
    a.archive(href='/arbeiten') Übersicht
    ul
      each article in articles
        if article.metadata.work
          li
            h3
              a(href=article.url)= article.title

【问题讨论】:

    标签: pug wintersmith


    【解决方案1】:

    普通翡翠iteration 应该可以做到这一点。您的代码的问题是变量名中不能有连字符。

    【讨论】:

      【解决方案2】:

      您可以限制传递给each 循环的元素数量:

      each article in articles.slice(0, 5)

      但在我看来,这种数据处理最好在视图生成之前进行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-06
        • 2015-07-11
        • 1970-01-01
        • 2021-08-05
        相关资源
        最近更新 更多