{block}
A named region of a layout or wrapper - and a page's override of it.
Syntax
{block 'name'} default content {/block}
{block 'name'} {parent} more content {/block}
Parameters
-
name -
The block's name, always quoted. A
{block}without a name is not a layout block.
Description
A {block 'name'} pair plays one of two roles, depending on where it stands. In a layout or a directory's _inits.pad/_exits.pad it is a region: its content is the default that renders unless something overrides it. A block standing directly in a page's own template - not inside another tag - is an override: it replaces the region of that name in the page's frame, the layout it {extends} or its directories' wrappers. Inside an override, {parent} is the content it replaces, so a page can add to a region instead of replacing it.
Like {extends}, the blocks are resolved in the text while the page is assembled and are gone before it renders, so they cost nothing at render time. This lets a page without any PHP set its wrapper's title: {block 'title'}Sales{/block} replaces the {block 'title'}...{/block} in the <title> of _inits.pad. A block of a page that overrides nothing stays where it stands and renders its content.
The name must be quoted: a {block} without one (the _common snippet of that name) is not a layout block. A block that reaches the render - one in a snippet or a custom tag's template, where nothing overrides it - simply renders its content. Under the strict check, a block of an extending page that overrides no block of the layout is an error, as is a block that never closes. What stands between {ignore} tags is left alone.
Examples
Overriding the regions
The layout has a title block and a footer block; the page replaces both.
{extends '_layouts/extendsCard'}
{block 'title'}Opening hours{/block}
{block 'footer'}Closed on public holidays{/block}
<p>Monday to Friday, 09:00 - 18:00.</p>
Opening hours
Monday to Friday, 09:00 - 18:00.
A block that overrides nothing
Without a layout, a block of a page that matches no region stays where it is and renders its content.
<p>Before the block.</p>
{block 'notice'}<p><strong>The shop is open as usual.</strong></p>{/block}
<p>After the block.</p>
Before the block.
The shop is open as usual.
After the block.
See also
- {extends} Frames the page with a layout instead of its directories' wrappers.
- {parent} Inside an overriding block: the content of the block it overrides.
- {slot} A named place in a custom tag's template - and the fill a caller gives it.
- {meta} The page's metadata - a title, a layout, a cache time or any value - read while the page is assembled.