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
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:
$view->set('chunk', $chunk_output); // if you want to set more than a single value, use setMultiple()
90
97
```
91
98
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
99
100
+
### Output markup of a chunk
101
+
102
+
A chunk is a reusable part of a template. That means you can use it multiple times between different template files.
103
+
Furthermore you could put contextual arguments as an array like `array('item' => $item, 'hello' => 'world')` into it.
104
+
105
+
```php
106
+
// in template file: /site/templates/view/template.tpl
$foo = 'do some logic // something with the contextual data';
143
+
$author = $this->page->createdUser;
144
+
145
+
$view->setMultiple( array(
146
+
'author' => $author,
147
+
'item' => $this->page,
148
+
'foo' => $foo
149
+
));
150
+
```
151
+
152
+
*/site/templates/view/chunks/nav-item.tpl*
153
+
```php
154
+
Author: <?= $author ?> <br />
155
+
<ahref="<?= $item->url ?>"title="<?= $foo ?>">
156
+
<?= $item->title ?>
157
+
</a>
158
+
```
159
+
93
160
## Important: Caching
94
161
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