You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -32,6 +32,7 @@ For each controller that is outputting markup, a corresponding template file sho
32
32
Depending on the setting "Global template file" of the activated engine, the factory tries to load the template file of the current page's controller or the global template file. If a template file is found, an instance of it is accessible over the API variable. If no template file is found, the factory assumes that the controller does not output markup over the template engine. In this case, the hook to modify the behaviour of Page::render() is not attached - everything works "normal".
33
33
34
34
The following example uses the ProcessWire template engine:
In the example above, some logic is processed if a form was sent. Note that there is no markup generated, because this should now be done by the corresponding template file! Over the new API variable `$view`, key/value pairs are passed to the template. Here is an example how the template file could look like:
56
+
48
57
```php
49
58
// In template file: /site/templates/view/home.php
50
59
@@ -60,6 +69,7 @@ In the example above, some logic is processed if a form was sent. Note that ther
60
69
<?php endif; ?>
61
70
```
62
71
Assume there is installed the module "TemplateEngineSmarty" and Smarty is chosen as the active template engine. The template file could look like this:
72
+
63
73
```php
64
74
// In template file: /site/templates/smarty/home.tpl
65
75
@@ -78,6 +88,7 @@ The introduced API variable acts as a gateway to the active template engine. Thi
78
88
79
89
### Load and output markup of other template files
80
90
Use the "TemplateEngineFactory" module to load any template file and output it's markup:
91
+
81
92
```php
82
93
// In controller file: /site/templates/product.php
$view->set('chunk', $chunk_output); // if you want to set more than a single value, use setMultiple()
90
101
```
91
102
The example above loads a template file called "product_chunk.tpl" and passes some variables. Calling "render()" returns the rendered markup of the template file.
92
103
104
+
### Output markup of a chunk
105
+
106
+
A chunk is a reusable part of a template. That means you can use it multiple times between different template files.
107
+
Furthermore you could put contextual arguments as an array like `array('item' => $item, 'hello' => 'world')` into it.
108
+
109
+
```php
110
+
// in template file: /site/templates/view/template.tpl
$foo = 'do some logic // something with the contextual data';
147
+
$author = $this->page->createdUser;
148
+
149
+
$view->setMultiple( array(
150
+
'author' => $author,
151
+
'item' => $this->page,
152
+
'foo' => $foo
153
+
));
154
+
```
155
+
156
+
*/site/templates/view/chunks/nav-item.tpl*
157
+
```php
158
+
Author: <?= $author ?> <br />
159
+
<ahref="<?= $item->url ?>"title="<?= $foo ?>">
160
+
<?= $item->title ?>
161
+
</a>
162
+
```
163
+
93
164
## Important: Caching
94
165
Since former ProcessWire templates are now controllers that generally do not output any markup, the ProcessWire template cache should *NOT* be active. Deactivate cache in the settings of your template under the section "Cache".
0 commit comments