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
Custom helpers could not be accessed directly inside Handlebars template #866
Comments
@kapooostin Thanks for the issue! If you're reporting a bug, please be sure to include:
If your issue is related to one of the following, please open an issue there:
|
To be clear, do you mean middleware handlers? e.g. |
No, I meant template helpers (Handlebars helpers to be precise), but mistyped it. I corrected the title. |
got it, thx. can you add a code example? helper and template, etc... |
//gulpfile task
app.helper( 'test', options => options.data.root ); {{ log ( test 'test' ) }} |
I rechecked and it seems the problem is in something else. I finished converting my helpers from legacy format. Now they are accessible without {{ log (getLayout) }} //prints an array as expected
{{#each (getLayout) as |block| }} //the loop never starts
...
{{/each}} |
thanks for the additional details, @doowb or I will check into this today |
Well, the main cause of trouble is my lack of experience with Gulp, I
guess. The error is thrown somewhere inside a loop in my template and the
task just silently fails.
I set up errors catching and do hope it will help.
|
Another mystery for me here: {{log data}} // prints out an object with a 'title' key
{{log (get 'title' data)}} // a helper from assemble/handlebars-helpers, outputs a correct value
{{log data.title}} // returns undefined |
@kapooostin is the code above your complete template? If any of those {{log ../data.title}} You can learn more about handlebars paths here. |
No, these 3 lines are at the beginning of the template. None of them is inside a loop or partial. Well, actually the whole template is a partial if it matters. |
yes, that might matter |
And data to this partial is passed from a helper. {{> block-section
data=(getContent block)
}} |
@kapooostin I've been looking into this. When using async helpers (like the To ensure that the async ids are resolved correctly, we provide built in partial rendering helpers. Use the built in helpers instead of the {{partial "block-section" (getContent block)}} Then inside your {{log this}}
{{log (get 'title' this)}}
{{log this.title}} If this doesn't work, then we have bug. |
Thank you, I'll try it now. Could we go the opposite way: render template
synchronously and make helpers synchronous? `getContent` is my custom
helper, so does it mean, that helpers are async by default?
|
yes, since
We've been discussing this at lot. When we first refactored assemble, we had both sync and async. but it was confusing and hard to maintain. We decided to go with async only, mainly because middleware handling was async, and we wanted to support consolidate. This meant that helpers would also have to support async rendering. Which is awesome, it works well usually, but there are also lots of edge cases cropping up. Here is what we're thinking:
Any feedback would be helpful |
Does async rendering support partial blocks? {{#> myPartial }}
Failover content
{{/myPartial}} |
I know almost nothing of async rendering so my feedback might be not very helpful. Is it possible to overload default partial syntax |
I'm pretty sure @doowb just mentioned something similar. maybe he has some thoughts on that.
feedback is always helpful! especially since you have a fresh perspective |
It worked, now I have to revamp all the partials to make it work. Maybe I'll try to prepare all the data before rendering to eliminate completely the use of helpers inside partials for data supplying. |
great, at least that part is working. let us know what you figure out, or if you have ideas for how to do it differently |
|
I was looking into this but it's harder than overriding helpers because handlebars users internal functions to handle partials. For now, using assemble's
I'm working on some documentation around explaining how async helpers work but the gist of it is: Wrap helpersWrap all registered helpers with a function that replaces the original helper so when it's called it:
This just returns the async id during the handlebars rendering ending up with a string that goes from: Upper: {{upper name}} to:
Resolve IdsNow that the template has been rendering to a string containing async ids, the ids need to be resolved.
CaveatsThere are a few things that we came across that drove the decisions on how async helper are used and how their ids are resolved:
After all of that, we're discussing ways to make async-helpers play nicely with the partial syntaxes. One way is to use the assemble |
Thank you for a such detailed overview of async helpers. I need some time to absorb it. |
@doowb can you add that information to the docs? |
Yeah, I'm working on it now. |
@doowb Has this info been added to the docs as of yet? Been over 1 year this ticket has been open |
ok, I think I understand what this is doing, but where do I resolve the asyncID's from? After being rendered, where do they end up living so I can do a |
{$ASYNCID$1$0$}
in a console output.My custom helper works correctly if I prefix its call with
helpers.
.The text was updated successfully, but these errors were encountered: