A tag of your own with a .pad template is a component: the caller's content goes where the template writes @content@. Named slots give it more than one place for content, and {parms} says which parameters it takes. The card below is _tags/card.pad:
{parms title, tone='plain'}
<div class="card {#tone}" style="border: 1px solid #999; padding: 6px; margin: 4px">
<b>{#title}</b>
{slot 'header'}<i>no header given</i>{/slot}
<div>@content@</div>
{slot 'footer'}<small>@content@</small>{/slot}
</div>
|
PHP |
HTML fragments/components_1.pad |
Result |
|---|---|---|
|
Monthly revenue
no header given
12.500
View report
Visitors
last 30 days
1.204
|
{slot 'footer'}...{/slot} pair standing directly in the content of the tag is a fill: it is taken out of the content and goes where the template has its {slot 'footer'}. The rest of the content goes to @content@.{slot} is its default, rendered when the caller gave no fill. {slot 'header'/} in the caller's content is an empty fill.{slot 'footer'}<small>@content@</small>{/slot} renders the frame round the fill, and nothing - or its @else@ part - when there is no fill.{#name} or a {slot} inside it belongs to the caller's tag - which is how a template passes a slot of its own on to a tag it uses.The fills belong to one use of the tag, so a card inside a card keeps its own footer:
|
PHP |
HTML fragments/components_2.pad |
Result |
|---|---|---|
|
Outer
no header given
Inner
no header given
inner body
inner footer
|
{parms title, tone='plain'} at the top of the template declares the parameters: a name alone is required, name=default fills in what the caller left out. Both read as {#title}.{card title='x', titel='y'} is reported by name.A component used on one page only needs no file of its own. {define 'name'}...{/define} writes it in the template: from there on {name} renders the body as _tags/name.pad would - {parms}, {#name}, @content@ and slots work alike.
|
PHP |
HTML fragments/components_3.pad |
Result |
|---|---|---|
|
New Sold out: 0 left |
A {macro} is called the way a function is: its parameters are declared on it - a name alone required, name=default filling in - given in their order or by name, and read as fields, {$label}.
|
PHP |
HTML fragments/components_4.pad |
Result |
|---|---|---|
|
{content} store does: a use before it is an unknown tag.