ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

data scope #62

Closed daslicht closed 10 years ago

daslicht commented 10 years ago

Hi, lets say we render a template like this:

                   res.render('addPage', {
                        title: 'Blog',
                        date: moment().format('MM-DD-YYYY'),
                        posts: items,
                        activeid :  "53963c600e91144721775c89"
                    }); 

How could we access activeid insinde this loop, please:

<div id="posts">
  {{#each posts}}
        {{> headline}}
  {{/each}}
</div>

any idea? maybe there is a better solution ?

ericf commented 10 years ago

@daslicht this is a limitation of Handlebars to not allow access to the root context. I'm working on a rewrite that will allow you to use the data "channel" to pipe data through:

res.render('addPage', {
  title: 'Blog',
  date: moment().format('MM-DD-YYYY'),
  posts: items,

  data: {
    activeid: '53963c600e91144721775c89'
  }
});
daslicht commented 10 years ago

thanks!