Fix an issue with {% elseif %} expressions inside fragments - #69
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Enhances the template compiler’s handling of conditional constructs inside fragments, fixing compilation/namespacing for {% if %} blocks with {% elseif %} chains and ensuring block extraction works for ifequal/ifnotequal within fragments. Adds regression tests and fixture templates covering these cases.
Changes:
- Fix fragment block namespacing for
ifnodes whoseElsebranch can be anelif-generated nested{'if', ...}AST node. - Include
ifequal/ifnotequalnodes in block traversal so nested blocks inside those conditionals are discovered. - Add new fragment templates and Common Test cases to validate
if/elseifrendering anduseblockbehavior underif/ifequal/ifnotequal.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/template_compiler.erl |
Fixes fragment element namespacing for elseif chains and enables block discovery under ifequal/ifnotequal. |
test/template_compiler_fragment_SUITE.erl |
Adds tests covering fragment rendering and useblock overrides for the new/adjusted conditional behavior. |
test/test-data/fragment_if.tpl |
Test fixture for {% if %}...{% elseif %}... inside a fragment. |
test/test-data/fragment_if_blocks.tpl |
Test fixture for blocks inside if/ifequal/ifnotequal fragments used via useblock. |
rebar.lock |
Updates cowlib lock version and hashes (appears unrelated to stated PR purpose). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request enhances the template compiler's support for conditional blocks within fragments, specifically adding support for
ifequalandifnotequalconstructs and improving howifblocks are handled. It also expands test coverage to ensure correct behavior for these new cases.Improvements to conditional block handling in fragments:
ifequalandifnotequalblocks within fragment definitions in thenamespace_fragment_elementandblock_elementsfunctions intemplate_compiler.erl. This ensures these constructs are correctly recognized and compiled when used inside fragments. [1] [2]Test coverage enhancements:
fragment_use_if_testandfragment_use_if_blocks_testtotemplate_compiler_fragment_SUITE.erlto verify correct rendering and block usage forif,ifequal, andifnotequalwithin fragments. [1] [2]fragment_if.tplandfragment_if_blocks.tplto serve as test data for the new test cases. [1] [2]