我正在使用docpad和索引页,在导航窗格中,我希望获得按类别分组的链接列表。
类别在每一个标记文档中定义在顶部的元信息中。例如,category:"tutorials"
所以我有这个:
<% for docu in @getFilesAtPath("document-repository").toJSON(): %>
<li><h2><%=cat=docu.category%></h2></li>
<%for docu in @getFilesAtPath("document-repository",category:cat}).toJSON():%>
<li><a href="#<%=docu.url%>"><%=docu.title%></a></li>
<%end%>
<% end %>但是,当然,它是坏的,因为它是循环的很多倍的文件,我有。我只有一个类别,我希望它只循环一次时,链接列表是打印的。
对于jekyll,它是这样完成的( _includes nav.html of https://github.com/devo-ps/carte):
{% for category in site.categories %}
<li><h2>{{ category | first }}</h2>
<ul>
{% for posts in category %}
{% for post in posts %}
<li class='{{ post.type }}'><a href='#{{ post.url }}'>{{ post.title }}</a></li>
{% endfor %}
{% endfor %}
</ul>
</li>
{% endfor %}他不知何故知道有多少类别。我不知道怎么把它移植到docpad
发布于 2014-04-01 04:19:19
我认为最好的问题是当你问完之后找到答案:)所以我找到了一个“解决办法”,至少我认为它是一个解决方案,而不是一个解决方案。对我来说这是完美的:
https://stackoverflow.com/questions/22766204
复制相似问题