1

Is it possible to add the site navigation to a partial file?

I like to keep things clean in my documents and really prefer seperating out the navigation but I have been having problems in Docpad when I add the navigation to the Partial file.

I am using Jade instead of eco. When I place the navigation in my default.html.md.jade file it works perfectly.

When I put the code in partials/nav.html.jade I get this error: warning: Something went wrong while rendering: html5-boilerplate.docpad/src/partials/nav.html.jade

And this shows up in the compiled HTML:

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

This is my navigation code:

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

And this is how I set up my collections inside docpad.coffee

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

            posts: (database) ->
                database.findAllLive({relativeOutDirPath:'posts'},[date:-1])
Daimz
  • 3,243
  • 14
  • 49
  • 76
  • Where is your `getCollection` function? – Ven May 18 '13 at 17:12
  • As far as I know it is collections: pages as above. I was looking at [link](https://github.com/docpad/twitter-bootstrap-jade.docpad) and how they did it their and based it off that. But I am really confused... I really want to use Jade with docpad but there is so little documentation on the two together it is proving really hard for me to understand – Daimz May 18 '13 at 20:00
  • Where is `getCollection` defined? You have `collections`, access it through `collections.Abc` – Ven May 18 '13 at 20:11

1 Answers1

3

Update: The Partials Plugin v2.8.0+ now includes the template data by default, so now things should just work without having to manually specify to include the template data. See the Partial Plugin page for more info.

By default, partials do not have any template data (for speed reasons). To get access to the template data, you can pass it over to the partial call like so (in eco, not familiar with jade): <%- @partial('the-partial-location', @) %>. You can also do it more precisely and performant by only passing over what you need like so: <%- @partial('the-partial-location', {something:@something, somethingElse: @somethingElse) %>

More info here

balupton
  • 47,113
  • 32
  • 131
  • 182