docpad / docpad-plugin-paged

Adds support to DocPad for rendering a document into multiple pages.
Other
28 stars 11 forks source link

Cannot read property 'number' of undefined #15

Closed ephimoff closed 9 years ago

ephimoff commented 10 years ago

Hi, Trying to use the plugin, but each time when there is a code like this

<% @document.page.number %>

I get the following error:

warning: Something went wrong while rendering: blog.html.eco
Cannot read property 'number' of undefined
error: Something went wrong with the action
error: An error occured: 
TypeError: Cannot read property 'number' of undefined
  at Object.eval (<anonymous>:45:25)
  at Object.eval (<anonymous>:65:8)
  at eval (<anonymous>:67:6)
  at Function.eco.render (/Users/antone/Sites/balupton/node_modules/docpad-plugin-eco/node_modules/eco/lib/index.js:26:25)
  at EcoPlugin.render (/Users/antone/Sites/balupton/node_modules/docpad-plugin-eco/out/eco.plugin.js:24:32)
  at ambi (/Users/antone/Sites/balupton/node_modules/docpad/node_modules/ambi/out/lib/ambi.js:25:27)
  at Task.<anonymous> (/Users/antone/Sites/balupton/node_modules/docpad/node_modules/event-emitter-grouped/out/lib/event-emitter-grouped.js:45:23)
  at ambi (/Users/antone/Sites/balupton/node_modules/docpad/node_modules/ambi/out/lib/ambi.js:23:18)
  at fire (/Users/antone/Sites/balupton/node_modules/docpad/node_modules/taskgroup/out/lib/taskgroup.js:163:25)
  at b (domain.js:183:18)
  at Domain.run (domain.js:123:23)
  at Task.fire (/Users/antone/Sites/balupton/node_modules/docpad/node_modules/taskgroup/out/lib/taskgroup.js:173:25)
  at processImmediate [as _immediateCallback] (timers.js:330:15)

What am I doing wrong? I couldn't find what should I add to the docpad.coffee to make it working. I use:

posts: ->
    @getCollection('documents').findAllLive({relativeOutDirPath:'blog'},[date:-1])
RobLoach commented 10 years ago

Are you using something like this then?

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

Make sure you have the pagedCollection stuff at the top of blog.html.eco too.

ephimoff commented 10 years ago

I use

posts: ->
    @getCollection('documents').findAllLive({relativeOutDirPath:'blog'},[date:-1])

I also use this code at the top of my blog.html.eco

---
layout: 'page'
title: 'Blog'
pageCount: 3
pageSize: 1
pagedCollection: 'posts'
---
ephimoff commented 10 years ago

Hey Rob,

Any thoughts about this? I really need your help with that. Or at least point me out where should I dig?

RobLoach commented 10 years ago

Could you try <% console.log @document %> ? You might be able to find what page data is available.

ephimoff commented 10 years ago

I did it and got lots of stuff in the console. The question is: what can I use to fix it? I tried to do that:

<% console.log @document.page %>

because I thought it'll show me something useful, but it didn't. Just got undefined. It seems that there is no object/method/attribute (whatever it is) .page

everthis commented 10 years ago

@ephimoff add "isPaged: true" to the meta area.

StormPooper commented 9 years ago

@ephimoff did @everthis' suggestion of adding isPaged: true fix it for you?

StormPooper commented 9 years ago

I'm closing this due to the amount of time that's passed with no word on if it's fixed, but if it's not, please comment and I'll reopen it.