Skip to content

Export push_partial_block and pop_partial_block#454

Open
mkantor wants to merge 1 commit into
sunng87:masterfrom
mkantor:custom-helpers-can-change-partial-block
Open

Export push_partial_block and pop_partial_block#454
mkantor wants to merge 1 commit into
sunng87:masterfrom
mkantor:custom-helpers-can-change-partial-block

Conversation

@mkantor

@mkantor mkantor commented Jul 12, 2021

Copy link
Copy Markdown
Contributor

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

@sunng87

sunng87 commented Jul 13, 2021

Copy link
Copy Markdown
Owner

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

mkantor commented Jul 15, 2021

Copy link
Copy Markdown
Contributor Author

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

sunng87 commented Jul 15, 2021

Copy link
Copy Markdown
Owner

@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

mkantor commented Jul 24, 2021

Copy link
Copy Markdown
Contributor Author

@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).

@mkantor mkantor force-pushed the custom-helpers-can-change-partial-block branch from 3f17405 to f548d96 Compare December 27, 2021 14:20
This allows custom helpers to manipulate the @partial-block variable.
@mkantor mkantor force-pushed the custom-helpers-can-change-partial-block branch from f548d96 to 943a75e Compare February 25, 2025 13:50
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 81.924%. remained the same
when pulling 943a75e on mkantor:custom-helpers-can-change-partial-block
into 6055df6 on sunng87:master.

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.

3 participants