Template inheritance just got a lot more flexible: layouts can now receive explicit variables, {embed} supports an implicit default block, and blocks finally behave intuitively in places where they used to fail. On top of that, the whitespace minifier behind {spaceless} has been rewritten from scratch to actually understand HTML.
✨ New Features
- {spaceless} rewritten from the ground up – the minifier now truly understands HTML, so it squeezes out much more whitespace without ever breaking your page: it strips whitespace completely around block elements, keeps proper word spacing around inline tags like
<i>or<a>, and leavespre,textarea,script,styleand attribute values untouched. And it streams, so even huge templates minify with no memory overhead. - Implicit default block for {embed} – content written directly inside
{embed}without a{block}wrapper now overrides{block default}of the embedded template, while an empty{embed}keeps the fallback (#419) - {layout file, vars} – pass explicit variables straight to the parent template:
{layout 'parent.latte', title: 'Hello'}. They reach the layout only (child blocks don't see them) and override same-named parameters. Works with{extends}too; note the comma before the arguments is required. - |json attribute modifier – JSON-encode a dynamic HTML attribute value with smart quoting:
<div data-config={$config|json}>
🐛 Bug Fixes
{include parent}and{include this}now work inside dynamically named blocks – previously this was a compile error, or worse, silently bound to an outer static block{contentType}inside<script>now really switches the escaping context – previously it was a silent no-op unless the script element had a matchingtypeattribute
🛠 For Extension Developers
- Every AST node now carries its full source extent:
Node::$positionmarks the start and the newNode::$endthe exclusive end;Rangeis a standalone start/end value object again (this reverts the shape shipped in 3.1.4)