2013-05-18 28 views
1

是否可以將網站導航添加到部分文件?將導航添加到Docpad中的部分內容

我喜歡將事情保持在我的文檔中,並且確實更喜歡分開導航,但是當我將導航添加到部分文件時,我一直在Docpad中遇到問題。

我使用的是Jade而不是eco。當我將導航放在我的default.html.md.jade文件中時,它完美地工作。

當我把代碼中的諧音/ nav.html.jade我得到這個錯誤: 警告:出了錯,而渲染:HTML5的boilerplate.docpad/src目錄/諧音/ nav.html.jade

這說明了在編譯的HTML:

<header>TypeError: Object #<Object> has no method 'getCollection'</header> 

這是我的導航代碼:

nav 
    ul 
     each doc in getCollection('pages').toJSON() 
      - clazz = (document.url === doc.url) ? 'active' : null 
      li(class=clazz) 
       a(href=doc.url, title=doc.title)= doc.title 

這就是我如何設置我的收藏裏docpad.coffee

collections: 
      pages: (database) -> 
       database.findAllLive({pageOrder: $exists: true}, [pageOrder:1,title:1]) 

      posts: (database) -> 
       database.findAllLive({relativeOutDirPath:'posts'},[date:-1]) 
+0

哪裏是你的'getCollection'功能? – Ven

+0

據我所知它是集合:頁面如上。我正在看[鏈接](https://github.com/docpad/twitter-bootstrap-jade.docpad)以及他們如何做到這一點,並以此爲基礎。但是我真的很困惑......我真的想用docpad來使用Jade,但是兩者的文檔很少,所以我很難理解 – Daimz

+0

getCollection定義在哪裏?你有'集合',通過'collections.Abc'訪問它 – Ven

回答

3

更新:諧音插件V2.8.0 +現在包括默認的模板數據,所以現在事情應該無需手動指定,包括模板數據只是工作。 See the Partial Plugin page for more info.

默認情況下,partials沒有任何模板數據(出於速度原因)。要訪問模板數據,您可以將它傳遞給部分調用(如eco,不熟悉玉):<%- @partial('the-partial-location', @) %>。你也可以做到更精確和高性能的特點是隻透過在您需要什麼,像這樣:<%- @partial('the-partial-location', {something:@something, somethingElse: @somethingElse) %>

更多信息here