我正在制作一个文件夹,并想简单地打印一个下一个和前一个项目的链接在每个项目的细节页面使用DocPad (使用骨干收集)。这里的代码来自my template projects.html.eco。@document对象是当前正在查看的文档。
<% for document in @getCollection('projects').toJSON() : %>
<% if document.url.indexOf('/posts') is @document.url.indexOf('/projects') + 1: %>
<a href="<%= document.url %>" class="next"><img src="/images/rt_arrow.png" alt="" /></a>
<% end %>
<% if document.url.indexOf('/posts') is @document.url.indexOf('/projects') - 1: %>
<a href="<%= document.url %>" class="previous"><img src="/images/lft_arrow.png" alt="" /></a>
<% end %>
<% end %>如果我能提供更多信息,请告诉我!
谢谢!
发布于 2012-09-27 12:36:06
似乎有一些事情正在发生:
/posts和/projects的组合,由于您正在循环的集合的名称,我认为它们都是/projects。+ 1和- 1仅应用于url中D9字符串的索引位置,而不是实际文档的索引。<代码>H210<代码>G211对于分页的解决方案,目前有可用的this gist,这应该会对您的用例有所帮助。将来,可以开发一个插件来提供您想要的简单next()和prev() jquery风格的应用程序接口。
https://stackoverflow.com/questions/12613499
复制相似问题