shannonmoeller / handlebars-layouts

Handlebars helpers which implement layout blocks similar to Jinja, Nunjucks (Swig), Pug (Jade), and Twig.
http://npm.im/handlebars-layouts
MIT License
361 stars 29 forks source link

Global template options not exposed to layout options. #23

Closed xquezme closed 9 years ago

xquezme commented 9 years ago

Not working:

<nav class="app-nav {{#block 'navClassName' mode='append'}}{{/block}}">
  <ul>
    {{#each links}}
      <li>{{intlGet labelPath}}</li>
    {{/each}}
  </ul>
</nav>
{{#extend "nav"}}
  {{#content "navClassName"}}app-nav-horizontal{{/content}}
{{/extend}}

Workaround:

<nav class="app-nav {{#block 'navClassName' mode='append'}}{{/block}}">
  <ul>
    {{#block 'links' mode='append'}}{{/block}}
  </ul>
</nav>
{{#extend "nav"}}
  {{#content "navClassName"}}app-nav-horizontal{{/content}}
  {{#content "links"}}
    {{#each links}}
      <li>{{intlGet labelPath}}</li>
    {{/each}}
  {{/content}}
{{/extend}}

See intlGet helper description

shannonmoeller commented 9 years ago

Have you tried using ../links or ../../links ?

<nav class="app-nav {{#block 'navClassName' mode='append'}}{{/block}}">
  <ul>
    {{#each ../links}}
      <li>{{intlGet labelPath}}</li>
    {{/each}}
  </ul>
</nav>
xquezme commented 9 years ago

Sure. Links not nested in this case.

<nav class="app-nav {{#block 'navClassName' mode='append'}}{{/block}}">
  <ul>
    {{#each links}}
      <li>{{log labelPath}}</li>
    {{/each}}
  </ul>
</nav>

Working as expected. Problem with intlGet helper, which required 'intl' object in options.

precompiledTemplate({
    links:[]
}, {
    data: {
      intl: LOCALE_CONTENT_HERE
    }
})
shannonmoeller commented 9 years ago

Glad to see you got it worked out.

xquezme commented 9 years ago

In fact the problem didn't go away.

xquezme commented 9 years ago

https://github.com/shannonmoeller/handlebars-layouts/pull/24

shannonmoeller commented 9 years ago

The options argument you recommend using in your PR isn't the way to go here. Any data passed that way gets prefixed with "@" and the helpers and partials are already in the global context.

http://handlebarsjs.com/execution.html

I'll need to throw together a test case, or see a gist of the relevant bits of your project, to see what's really happening.

shannonmoeller commented 9 years ago

@xquezme Any chance the latest release fixes your issue?

xquezme commented 9 years ago

Nope.

shannonmoeller commented 9 years ago

Ok. Just released 3.1.2 which I hope will also fix your issue. Mind taking another look?