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

Automatically inject the associatedfiles array into the document object #7

Open
RobLoach opened this issue Feb 12, 2014 · 7 comments
Open

Comments

@RobLoach
Copy link
Contributor

Have the associated files automatically load and be available rather than having to call getAssociatedFiles().

@balupton
Copy link
Member

We actually did this in early versions of the plugin, however dumping meta or template data in pre-emptively, rather than as requested, caused memory issues.

The standard since, has been plugins should expose data via template helpers instead. We just need to update plugins to do this from now on. E.g. the feedr plugin should instead of doing @feedr.feeds, instead it should be getFeedr().feeds or the like.

@RobLoach
Copy link
Contributor Author

🔒

@RobLoach RobLoach reopened this Feb 16, 2014
@RobLoach
Copy link
Contributor Author

@balupton How does one retrieve the associated files from a Collection? I've set up a Paged collection using the Paged plugin, but it doesn't load a DocumentModel.

    <% for document in @getPageCollection(@document.pagedCollection).toJSON(): %>
        <% console.log document.getAssociatedFiles() %>
    <% end %>

getAssociatedFiles is not defined.

@balupton
Copy link
Member

The problem here is the toJSON(), which means that you are no longer working with the model, but with a plain javascript object. Remove that, and you'll be good to go:

    <% for documentModel in @getPageCollection(@document.pagedCollection): %>
        <%- JSON.stringify documentModel.getAssociatedFiles() %>
    <% end %>

@rustycoat
Copy link

@balupton - I'm so glad to find your answer here, as I've been searching out this problem for hours, but I still must be doing something wrong. This doesn't seem to be solving the problem for me.

If I try the most basic query:

<% for documentModel in @getCollection("documents") : %>
    <% documentModel.getAssociatedFiles() %>
<% end %>

I get.

TypeError: Cannot call method 'getAssociatedFiles' of undefined at Object.eval (<anonymous>:47:23)

Nonetheless, it appears it's getting the exact number of objects that it should. If I call toJSON() on the collection then the iterated object appears to be functional otherwise, but I of course can't call any methods on it. If I don't call toJSON() on the collection then it appears very confused as to the objects model -- it will not allow me to access .title or any field or call any methods on 'undefined' but iterates the right amount of times. Is there a definition for DocumentModel that I need to pull in, perhaps -- I am doing this from within a document.

(I am new to Javascript/json/node -- my apologies if I am missing some obvious convention).

@balupton
Copy link
Member

balupton commented Apr 2, 2014

Try this @getCollection("documents").models, it's a backbone.js thing.

@rustycoat
Copy link

Works beautifully, thanks... now that I've got my debugger working too it's a lot easier to find out object prototypes so that I can look up documentation as needed, too... it's been frustrating as there are a lot of patterns/conventions/etc that I'm just not aware of and don't know what dependencies documentation to look in. The documentation for docpad could use a little bit more improvement, though the little getting started guide is one of the better ones I've read for a framework...

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants