2012-09-27 24 views
4

我正在做一个投资组合,并希望简单地打印使用DocPad(使用骨干集合)每个项目详细信息页面上的次&以前的项目链接。这里的代码是从我的模板projects.html.eco。所述@document对象是当前正在观看的文档。获取收集下一个和以前的文件与docpad

<% 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 %> 

让我知道如果我可以提供任何更多的信息!

谢谢!

回答

1

好像有几件事情怎么回事:

  1. 。在你的比较中使用的/posts/projects组合,我会跟他们都意味着是/projects因您正在骑车的集合的名称。

  2. + 1- 1您目前只适用于url中的/projects字符串的索引位置,而不是实际文档的索引。

对于寻呼解决方案,目前this gist可用,这应有助于为您的使用情况。在未来,一个插件可以做起来,以提供简单next()prev()的jQuery风格的API你后。

+0

谢谢你,这个完美! –

相关问题