Skip to content

Fix an issue with {% elseif %} expressions inside fragments - #69

Merged
mworrell merged 1 commit into
masterfrom
fragment-elsif-fix
Jun 15, 2026
Merged

Fix an issue with {% elseif %} expressions inside fragments#69
mworrell merged 1 commit into
masterfrom
fragment-elsif-fix

Conversation

@mworrell

Copy link
Copy Markdown
Member

This pull request enhances the template compiler's support for conditional blocks within fragments, specifically adding support for ifequal and ifnotequal constructs and improving how if blocks are handled. It also expands test coverage to ensure correct behavior for these new cases.

Improvements to conditional block handling in fragments:

  • Added support for namespacing and processing ifequal and ifnotequal blocks within fragment definitions in the namespace_fragment_element and block_elements functions in template_compiler.erl. This ensures these constructs are correctly recognized and compiled when used inside fragments. [1] [2]

Test coverage enhancements:

  • Added new test cases fragment_use_if_test and fragment_use_if_blocks_test to template_compiler_fragment_SUITE.erl to verify correct rendering and block usage for if, ifequal, and ifnotequal within fragments. [1] [2]
  • Introduced new template files fragment_if.tpl and fragment_if_blocks.tpl to serve as test data for the new test cases. [1] [2]

Copilot AI review requested due to automatic review settings June 15, 2026 08:50
@mworrell mworrell self-assigned this Jun 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 if nodes whose Else branch can be an elif-generated nested {'if', ...} AST node.
  • Include ifequal/ifnotequal nodes in block traversal so nested blocks inside those conditionals are discovered.
  • Add new fragment templates and Common Test cases to validate if/elseif rendering and useblock behavior under if/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.

@mworrell
mworrell merged commit 7dffacb into master Jun 15, 2026
4 checks passed
@mworrell
mworrell deleted the fragment-elsif-fix branch June 15, 2026 08:54
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.

2 participants