Layouts: extends, block and parent
The directories give a page its frame - every _inits.pad and _exits.pad on the way to it. A layout is a frame the page picks itself, wherever it lives, and whose regions it can override one by one. This is _layouts/report.pad:
<div style="border: 1px solid #999; padding: 6px">
<h3>{block 'title'}Report{/block}</h3>
<div>{block 'sidebar'}<a href="?index">Home</a>{/block}</div>
@page@
<small>{block 'footer'}Generated by PAD{/block}</small>
</div>
A page that extends it fills in the title, adds to the sidebar and leaves the footer as it is:
|
PHP |
HTML fragments/layouts_1.pad |
Result |
|---|---|---|
|
The three tags
-
{extends '_layouts/report'}- the page is framed by that layout instead of by its directories' wrappers. The layout is named from the application root, like a{page}; an underscore directory keeps it from being a page of its own. A layout may extend another layout. -
{block 'name'}...{/block}in the layout is a region: its content renders unless the page overrides it. The same pair standing directly in the page is an override. The name is always quoted. -
{parent}inside an override is the content it overrides - to add to a region instead of replacing it.
What the page holds outside its blocks goes where the layout writes @page@, or in front of the layout when it has none.
Blocks in the directory wrappers
The blocks of an ordinary _inits.pad are regions too, so a page that extends nothing still overrides them: with <title>{block 'title'}My site{/block}</title> in the wrapper, a page sets its own title with {block 'title'}Sales{/block} - no PHP needed. A block of such a page that overrides nothing renders where it stands.
Resolved before rendering
Blocks are put together in the text while the page is assembled, before anything renders, so they cost nothing at run time. Under the strict check a block of an extending page that overrides nothing is reported - usually a misspelt name - and so is an {extends} inside another tag, where the assembly does not look.