feat: add block and blockAsync template helpers - #367
Merged
Conversation
Add override-able named blocks for layouts. Child templates define block overrides via block(name, fn), layouts define slots with optional defaults. Built on top of the capture/captureAsync primitives. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #367 +/- ##
==========================================
+ Coverage 91.46% 92.15% +0.68%
==========================================
Files 11 11
Lines 293 293
Branches 78 78
==========================================
+ Hits 268 270 +2
Misses 9 9
+ Partials 16 14 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This was referenced Apr 25, 2026
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.
Summary
block(name, fn?)andblockAsync(name, fn?)helpers for Nunjucks/Blade-style named blocks in layoutscapture/captureAsyncprimitives from feat: add capture and captureAsync template helpers #365 — no new parsing logicUsage
Child template:
Layout template:
If the child defines a block, it overrides the layout default. If not, the default runs. If neither provides content, the block renders as an empty string.
Changes
src/compile-string.ts— addblocks: {}to__eta, injectblock/blockAsyncfunctions, pass__blocksto layout render calltest/compile-string.spec.ts— update 4 compiled output snapshotstest/render.spec.ts— add 7 tests (override, default, empty, multiple blocks, data access, no body leakage, async)Test plan
Closes #245
🤖 Generated with Claude Code