-
Notifications
You must be signed in to change notification settings - Fork 2k
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 named child helpers that can be referenced by block helpers #404
Comments
Hey @jhudson8, I haven't tried it yet, but @thejohnfreeman has a pretty promising-looking approach which should satisfy your use case. Check out the details in his blog post and look for tips on how to implement it in the related issue. Hope that helps! |
Thanks @dmarcotte, it certainly seems that the author is experiencing some of the pain that I am but I am looking for a less half-baked approach (no offense intended to the author). Unless I'm misunderstanding, the child block names can not be reused with this solution. I would like to be able to do something like:
and have the ability to control what happens with header in the helper definition. Regardless, I appreciate your comment - thanks. I am going to try to implement this but I know nothing of the handlebars internals. If I get this done, I'll add a comment with the PR branch. If you are interested in this, feel free to comment with syntax suggestions (and impl suggestions for that matter). |
Alas, I'm not going to be able to come up with a good solution as I can't even get Handlebars to build due to some issue with the 'therubyracer' dependancy. I really hope that someone with access and Handlebars skills add this type of functionality because it seems like it would be super useful. In the meantime, I've come up with a ghetto solution.
with a usage of
It has a few issues though:
|
What is it that you want exactly? Your example seems incomplete. I think there's something implied that I'm just not understanding. {{#section}}
{{#child 'header'}}...{{/child}}
{{#child 'body'}}...{{/child}}
{{#child 'footer'}}...{{/child}}
{{/#section}} Is this a reusable block? Is it supposed to be a stand-alone example? It looks like it would produce no output. I'm just not getting it. :/ |
The section helper will basically call it's block function 3 times (with a specific mode attribute; "header", "body", "footer"). The child helper will not render anything unless the mode attribute matches the child helper's expected mode. The parseMode function (called by the section helper) sets up the context with the mode attribute and calls the section helper block function (provided as param). However, I have come up with a use case which I believe is much more applicable and can not be solved by my solution. I would like to be able to do the following:
With a helper like something as follows (just an initial thought)
IMHO, if Handlebars had this functionality - it would be unbeatable. Question: is it appropriate to rewrite the description of this issue with the new use case or close this task and create a new one for posterity? |
note: I just changed the example child parameter block identifiers from '@' to '*' as I didn't realize that {{@...}} was existing Handlebars syntax. |
@jhudson8 my thought was that you could do this with the
But it turns out this won't work because you can't pass a helpers hash to |
@eastridge I like where you are going with this. This would work if you could pass a helpers hash. |
Closing in favor of #1018 |
It would be nice if we could define named blocks that could be referenced within a Handlebars helper. I'll use, for example, a special prefix
{{@
to defined the child helper. An example would be:And, for example, the nested helpers could be referenced in this way:
The text was updated successfully, but these errors were encountered: