Closed justb3a closed 8 years ago
setMultiple
$view->setMultiple(array( 'posts' => $posts, 'hello' => 'world' ));
renderChunk
template file: /site/templates/view/template.twig
<?php foreach ($nav_pages as $p): ?> <?php $page->renderChunk('chunks/nav-item', array('page' => $p)); ?> <?php endforeach; ?>
/site/templates/chunks/nav-item.php
<?php namespace ProcessWire; $foo = 'do some logic // something with the contextual data'; $author = $this->page->createdUser; $view->setMultiple( array( 'author' => $author, 'item' => $this->page, 'foo' => $foo ));
/site/templates/view/chunks/nav-item.tpl
Author: <?= $author ?> <br /> <a href="<?= $item->url ?>" title="<?= $foo ?>"> <?= $item->title ?> </a>
Note: I had to access \ProcessWire\TemplateFile. I guess, this won't work using the 2.x branch because of it's lacking namespace support.
\ProcessWire\TemplateFile
Added a
setMultiple
method inside the factory to be able to submit more than one property at once:Added a
renderChunk
method to be able to render and reuse template partials.template file: /site/templates/view/template.twig
/site/templates/chunks/nav-item.php
/site/templates/view/chunks/nav-item.tpl
Note: I had to access
\ProcessWire\TemplateFile
. I guess, this won't work using the 2.x branch because of it's lacking namespace support.