Skip to content

Support Jinja2-style elif in conditionals#339

Open
mrowrpurr wants to merge 2 commits into
pantor:mainfrom
mrowrpurr:elif-support-for-more-jinja2-compatibility
Open

Support Jinja2-style elif in conditionals#339
mrowrpurr wants to merge 2 commits into
pantor:mainfrom
mrowrpurr:elif-support-for-more-jinja2-compatibility

Conversation

@mrowrpurr

@mrowrpurr mrowrpurr commented Jun 20, 2026

Copy link
Copy Markdown

inja supports chained else if, but Jinja2 rejects that syntax:

jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got 'if'

Jinja2 only accepts elif. This adds elif as a synonym for else if, improving Jinja2 compatibility.

  • Both spellings work and can be mixed in the same chain — existing templates are unaffected
  • The new elif parser branch mirrors the existing chained else if handling
  • Tests cover basic elif, chains, elifelse, mixed else if/elif, and the elif without matching if error
  • README and the regenerated single-header are updated

mrowrpurr and others added 2 commits June 20, 2026 07:34
inja already supports chained `else if`, but that syntax is rejected by
Jinja2. Rendering an `else if` template through Jinja2 raises:

    jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got 'if'

Jinja2 only accepts `elif`. To improve Jinja2 compatibility, this adds
`elif` as a synonym for `else if`. Both spellings are supported and can be
mixed within the same conditional chain, so existing templates are
unaffected.

The new `elif` branch in the parser mirrors the existing chained `else if`
handling: it marks the false-statement block, creates a nested
IfStatementNode, and parses the condition. Tests cover basic `elif`,
`elif` chains, `elif` followed by `else`, mixed `else if`/`elif` chains,
and the `elif without matching if` error. README and the regenerated
single-header amalgamation are updated to match.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mrowrpurr mrowrpurr marked this pull request as ready for review June 20, 2026 14:59
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.

1 participant