Search code examples
pugpartialdocpad

Adding navigation to a partial in Docpad


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])

Solution

  • 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