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

Export push_partial_block and pop_partial_block #454

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mkantor
Copy link
Contributor

@mkantor mkantor commented Jul 12, 2021

This allows custom helpers to manipulate the @partial-block variable.

@sunng87
Copy link
Owner

sunng87 commented Jul 13, 2021

May I know your use case for this? Since @partial-block is an internal mechanism in handlebars. Exposing these API may allow developers to change its meaning of it

@mkantor
Copy link
Contributor Author

mkantor commented Jul 15, 2021

Exposing these API may allow developers to change its meaning of it

That's my goal. 😄

I have a custom helper that can render other handlebars templates (with additional functionality), and want to set @partial-block so it behaves more like > (mkantor/operator#10 (comment)).

Here's the commit where I'd like to use push_partial_block: mkantor/operator@bd80936#diff-6d2087fee5a1b9f51fa4201717f8bbc6abea61b7a185437a0bb50da97bb00c0e

@sunng87
Copy link
Owner

sunng87 commented Jul 15, 2021

@mkantor Thanks for your clarification. How about using set_partial from RenderContext to register the template as a partial in your helper? The only drawback I think is you cannot use @partial-block this way but it makes sense because @partial-block has it own meaning within handlebars system.

@mkantor
Copy link
Contributor Author

mkantor commented Jul 24, 2021

@sunng87 Sorry for the slow response!

How about using set_partial from RenderContext to register the template as a partial in your helper? The only drawback I think is you cannot use @partial-block this way

I could use set_partial with a different name (that's what I did while prototyping), but I was hoping to specifically use @partial-block to make it easier to migrate between > and my get helper. My goal is to not require any changes in the included template when you do that.

@partial-block has it own meaning within handlebars system

To me this doesn't feel much different from a helper that sets variables like @index or @key, but I may be missing something.

For what it's worth handlebars.js allows this (there it's much worse because the global Handlebars object gets mutated).

This allows custom helpers to manipulate the @partial-block variable.
@mkantor mkantor force-pushed the custom-helpers-can-change-partial-block branch from 3f17405 to f548d96 Compare December 27, 2021 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants