This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
documentation:rack:reference:templates [2018/05/25 20:10] – [More functionality] Martijn Luinstra | documentation:rack:reference:templates [2023/08/31 23:12] (current) – Martijn Luinstra | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Templates ====== | ====== Templates ====== | ||
- | Every template is an instance of the <php>Template</ | + | Every template is an instance of the '' |
+ | |||
+ | <WRAP danger> | ||
===== Template variables (context) ===== | ===== Template variables (context) ===== | ||
Line 7: | Line 9: | ||
Templates are intitialized with a context object, which is an associative array. The individual elements of this array are made available in the templates as regular variables (see [[http:// | Templates are intitialized with a context object, which is an associative array. The individual elements of this array are made available in the templates as regular variables (see [[http:// | ||
- | <PHP> | + | <code php> |
$context = [ | $context = [ | ||
' | ' | ||
' | ' | ||
]; | ]; | ||
- | </PHP> | + | </code> |
and the template | and the template | ||
- | <PHP> | + | <code php> |
< | < | ||
< | < | ||
Line 26: | Line 28: | ||
</ | </ | ||
</ | </ | ||
- | </PHP> | + | </code> |
which renders as | which renders as | ||
- | <HTML> | + | <WRAP box round> |
- | <div style=" | + | ====== Home ====== |
- | <h1>Home</h1> | + | page_id: index |
- | page_id: index | + | </WRAP> |
- | </div> | + | |
- | </HTML>\\ | + | |
===== Template functions ===== | ===== Template functions ===== | ||
- | The following | + | All global |
- | * <php>html($data)</ | + | |
- | * <php>attr($data)</ | + | * '' |
- | * <php>format_plain_text($text)</ | + | * '' |
- | * < | + | |
- | **WARNING! No data is escaped by default. Always escape your template variables. | + | Remember! No data is escaped by default. Always |
The following snippet shows how these functions should be used. | The following snippet shows how these functions should be used. | ||
- | <PHP> | + | <code php> |
< | < | ||
< | < | ||
<?= $this-> | <?= $this-> | ||
- | | + | Author: <a href="<? |
- | | + | |
</ | </ | ||
- | </PHP> | + | </code> |
Line 64: | Line 62: | ||
Rack templates support basic template inheritance, | Rack templates support basic template inheritance, | ||
- | * <php>Template-> | + | * '' |
- | * <php>Template-> | + | * '' |
- | * <php>Template-> | + | * '' |
Note that nested blocks are not supported and that blocks are only allowed in templates that extend a parent template. | Note that nested blocks are not supported and that blocks are only allowed in templates that extend a parent template. |