← Alle berichten

Views learn to think

A view has been a string with holes in it: HTML, variables, nothing else. Conditionals and loops meant leaving the view and assembling markup in a method. Now the control structures are part of the language, written as tags so the template still reads as markup:

<if $this->showChildren>
    <foreach $this->childList AS $column => $child>
        {{ CMS($child->obj, 'listing', $this, records: $this->record->$column) }}
    </foreach>
</if>

Writing them as <if> and <foreach> rather than as escaped PHP is the choice that matters. The view stays scannable as HTML, the nesting is visible to your editor's tag matching, and a closing tag tells you what it closes.

The transpiler tracks block depth to make that work, and does one thing beyond the obvious: it compensates the indentation, so the generated HTML comes out as neatly indented as the source. Output you can read in the browser's inspector is not decoration; it is the difference between debugging your page and debugging your template.

The same release brings the shorthand that keeps views short. <div#main.small.red/> expands to the full attributes, and attributes never needed quotes. Interpolation settles into two forms: {{ }} for a value, {( )} for an expression inside an attribute.

See the Views chapter.

We gebruiken essentiële cookies om deze site te laten werken. Met uw toestemming gebruiken we ook analytics om de site te verbeteren.