Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add params to #embed #14

Closed
baldore opened this issue Jan 16, 2015 · 3 comments
Closed

Add params to #embed #14

baldore opened this issue Jan 16, 2015 · 3 comments

Comments

@baldore
Copy link

baldore commented Jan 16, 2015

Hi, is there a way to add params or data to the embeds, just like this???

Component

<div>
  <h2>I'm visible</h2>
  {{#if hideTitle}} <h2>Hide me!!! if you can...</h2> {{/if}}
  {{#block "content"}}{{/block}}
</div>

Implementation

{{#embed "component" hideTitle=true}}
  {{#content "content"}}<h4>This is the new way</h4>{{/content}}
{{/embed}}

Result

<div>
  <h2>I'm visible</h2>
  <h4>This is the new way</h4>
</div>

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.

@shannonmoeller
Copy link
Owner

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.

handlebars-lang/handlebars.js#182

@shannonmoeller
Copy link
Owner

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}}

@shannonmoeller
Copy link
Owner

Feature added and released as 1.1.0.

Repository owner locked and limited conversation to collaborators Apr 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants