Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to call @getCollection("partials") from docpad.coffee #8

Open
patocallaghan opened this issue May 22, 2013 · 6 comments
Open
Labels

Comments

@patocallaghan
Copy link
Contributor

Hey,

I've come across an issue where it seems that I can't define a collection in my docpad.coffee that tries to access partials e.g. @getCollection('partials').

By chucking in some debug statements it seems that the functions for the collections in docpad.coffee are running before PartialsPlugin.populateCollections is called so it's always undefined. But instead if I call @getCollection from within one of my documents it works fine.

//Fails in docpad.coffee, returns undefined
collections:
     objects: ->
            @getCollection("partials").findAllLive({isObject:true})

//Works okay in index.html.eco
<% for object in @getCollection("partials").findAllLive({isObject:true}).toJSON(): %>

I've attached a debug log here.

If you want to replicate the issue it's occurring on my repo here. You'll just have to uncomment the collections in docpad.coffee.

Thanks,
Pat

@balupton
Copy link
Member

Could be that the partials plugin hasn't been able to create the partials plugin yet. However, you can change your query to @getCollection('html').findAllLive(isObject:true, partial:true) - does that work? As the partials plugin should inject partial:true into the in memory meta data for all the partials :)

@patocallaghan
Copy link
Contributor Author

Are you saying to add that into the docpad.coffee or the .eco file?

Adding the suggested statement runs without any errors in docpad.coffee unlike the original query, but when I run @getCollection('objects') within my .eco file it comes back empty.

Actually, I've just tried it and running that query in my .eco comes back empty anyway.

@balupton
Copy link
Member

Sorry I mustn't have been clear enough.

docpad.coffee

collections:
     objects: (database) ->
            database.findAllLive({partial:true, isObject:true})

index.html.eco

<% for object in @getCollection("objects").toJSON(): %>

@patocallaghan
Copy link
Contributor Author

That didn't seem to make a difference either..See the branch I have here with those changes. index.html.eco is in src/documents.

@saviomuc
Copy link

saviomuc commented Aug 7, 2013

I am having the exact same Problem here. I tried to get a collection of all partials with the metatag "isObject"

collections:
     docu: (database) ->
                 database.findAllLive({partial:true, isObject:true})

and call it within a template that uses the paged plugin. This Plugin expects a collection name

---  
pagedCollection: 'docu'
---

Console returns undefined for me

@rhythmus
Copy link

Not exactly the same use case, but seems a related issue with the partials plugin.

From within a partials/header.html.md.eco file (template for a reusable contextual site menu), we run a query as follows:

<ul>
    <% for page in @getCollection("menu").toJSON(): %>
        <li class="<%= if page.id is @document.id then 'active' else 'inactive' %>">
            <a href="<%= page.url %>">
                <%= page.title %>
            </a>
        </li>
    <% end %>
</ul>

Then we use this partial in a default.html.eco layout:

<%- @partial('header.html.md.eco')%>

Unfortunately it outputs: TypeError: Object # has no method 'getCollection'. And in the logs: warning: Something went wrong while rendering: header.html.md.eco.

When we do the same not from within a partial, but right away in the layouts/default.html.eco file , then there is no problem, and we get the desired output.

Update: Adding @ (~ this) solved it: <%- @partial('header.html.md.eco', @)%> (cfr #3 (comment)).

@mikeumus mikeumus added the bug label Apr 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants