Closed baldore closed 9 years ago
The context is passed into {{#extend}}
and {{#embed}}
, but you may need to use ../
segments to get to the values you're looking for. That said, the ability to pass in arbitrary values via attributes, which is now supported by the baked in partials syntax ({{> partialName}}
), is useful. I'll add it.
wycats/handlebars.js#182
In the meantime, this workaround should provide the functionality you're looking for in your example case.
{{!-- component --}}
<div>
<h2>I'm visible</h2>
{{#block "title"}}<h2>Hide me!!! if you can...</h2>{{/block}}
{{#block "content"}}{{/block}}
</div>
{{!-- usecase --}}
{{#embed "component"}}
{{#content "title"}}{{/content}}
{{#content "content"}}<h4>This is the new way</h4>{{/content}}
{{/embed}}
In the usecase, defining an empty block will replace the title
in the component with an empty string. You might also be able to wrap it in a conditional, but I've honestly never tried this:
{{!-- usecase --}}
{{#embed "component"}}
{{#if ../someValue }}
{{#content "title"}}{{/content}}
{{/if}}
{{#content "content"}}<h4>This is the new way</h4>{{/content}}
{{/embed}}
Feature added and released as 1.1.0.
Hi, is there a way to add params or data to the embeds, just like this???
Component
Implementation
Result
Or maybe you can pass the context??? I don't know much about Handlebars so, if this functionality already exist, can you give a example??? Thanks a lot.