Skip to content

feat: Added dynamic partial blocks by adding support for empty block closing tags#713

Merged
sunng87 merged 5 commits intosunng87:masterfrom
henriquecolini:master
Jun 11, 2025
Merged

feat: Added dynamic partial blocks by adding support for empty block closing tags#713
sunng87 merged 5 commits intosunng87:masterfrom
henriquecolini:master

Conversation

@henriquecolini
Copy link
Contributor

@henriquecolini henriquecolini commented May 25, 2025

This PR implements a feature that has been historically lacking from the original Handlebars: dynamic partial blocks. handlebars-lang/handlebars-parser#9

Handlebars syntax allows users to create both dynamic partials:

{{> (snake_case 'MyPartial') }}

And partial blocks:

{{#> my_partial }}
    Hello
{{/my_partial}}

In theory, one should be able to use both features at the same time since there's no conflict whatsoever betwen them. In practice though, this turns out to be impossible due to a funny oversight in the syntax:

{{#> (snake_case 'MyPartial') }}
    Hello
{{/ ??? }}
what goes here?

I have fixed this issue by making the explicit name in the closing tag optional, which I consider the most obvious change to the syntax. So, this is now possible:

{{#> (snake_case 'MyPartial') }}
    Hello, this works now!
{{/}}

And as a bonus, it's also possible in general, for any partial and decorator block:

{{#> my_partial }}
    {{#*inline foo }}
        some inline stuff
    {{/}}
{{/}}

@coveralls
Copy link

coveralls commented Jun 6, 2025

Coverage Status

coverage: 82.399%. first build
when pulling 1c92f2d on henriquecolini:master
into 888ed6a on sunng87:master.

Copy link
Owner

@sunng87 sunng87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks mostly good to me. Just add two small comments

@sunng87 sunng87 merged commit af666e2 into sunng87:master Jun 11, 2025
8 checks passed
@sunng87
Copy link
Owner

sunng87 commented Jun 11, 2025

@henriquecolini I just reverted the version change by myself. Thank you for the patch!

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