carrot / roots-records

Parse JSON conveniently as roots locals to be used with any template engine.
Other
24 stars 10 forks source link

`records` local is empty array inside layout and single-view template files #15

Open zspecza opened 9 years ago

zspecza commented 9 years ago

:hankey:

index.jade - records = [...] - local behaves as expected. layout.jade - records = []

With settings:

categories:
        url: retrieve_models 'Category'
        template: 'views/_category.jade'
        collection: (categories) ->
          categories = categories.filter filter_current_locale
        out: (category) ->
          "/articles/categories/#{category.title.toLowerCase().replace(/ /g, '-')}"
        hook: (categories) ->
          categories = categories.filter filter_current_locale

Inside _page.jade: records.categories === undefined.

bleeppurple commented 9 years ago

I am also receiving this error

jescalan commented 9 years ago

I'm not entirely clear on what this error is describing, I'm sorry! I assume you mean something else, but on template pages, you use item rather than records according to the docs.

bleeppurple commented 9 years ago

Sorry Ill run through a little example

say I two records / services, one for posts and one for news items

extensions: [
    js_pipeline(files: 'assets/js/*.coffee', out: 'js/build.js', minify: true, hash: true),
    css_pipeline(files: 'assets/css/theme.css')
    records({
      news_feed: {url: 'http://service.co.uk/content/modules/news/'}
      pages: {
        url: 'http://service.co.uk/content/pages/'
        template: "views/_temp.jade"
        collection: (d) -> d.data
        out: (page) -> "/pages/#{S(page.title).slugify().s}"
      }
    })
  ]

The locals I see on the index and single page templates

index.jade - records = [...] - local behaves as expected. 
index.jade - item = null local behaves as expected.

post.jade - item = [...] - local behaves as expected.
post.jade - records = null

What happens if I want to use my news feed service inside my (single) post view I cant access it because I dont have access to records

jescalan commented 9 years ago

Got it. So essentially, when you are compiling out single view from roots-records, you want to have access to item as well as the base records object? I have been able to reproduce this error on one of my projects -- this is the same one you guys are talking about?

Either way, I will close out the one I'm describing today :grinning:

bleeppurple commented 9 years ago

Yes you've got it spot on :) I wasnt expecting you to sort it so soon , I moved away from roots for this project but Ill be back to it again..thanks for open sourcing it

Jamie

On Mon, Jul 27, 2015 at 3:01 PM, Jeff Escalante notifications@github.com wrote:

Got it. So essentially, when you are compiling out single view from roots-records, you want to have access to item as well as the base records object? I have been able to reproduce this error on one of my projects -- this is the same one you guys are talking about?

Either way, I will close out the one I'm describing today [image: :grinning:]

— Reply to this email directly or view it on GitHub https://github.com/carrot/roots-records/issues/15#issuecomment-125217081 .

jescalan commented 9 years ago

Ah sorry about that. Would have fixed it earlier honestly, but I'm working part time this year! Will update here shortly when it's resolved :grinning:

bleeppurple commented 9 years ago

No worries appreciate it.. glad you can fix it at all

On Mon, Jul 27, 2015 at 3:24 PM, Jeff Escalante notifications@github.com wrote:

Ah sorry about that. Would have fixed it earlier honestly, but I'm working part time this year! Will update here shortly when it's resolved [image: :grinning:]

— Reply to this email directly or view it on GitHub https://github.com/carrot/roots-records/issues/15#issuecomment-125224513 .

jescalan commented 9 years ago

This has been fixed in #23 and a test is in place to prevent any regression. Will be merged and available to everyone today :tada: