2012-09-27 26 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

謝謝你,這個完美! –

相關問題