ProcessWire - Page Rendering Functions

Aus Wikizone
Version vom 4. September 2018, 14:17 Uhr von 109.193.234.155 (Diskussion) (Die Seite wurde neu angelegt: „ https://processwire.com/talk/topic/13958-help-understanding-render-and-rendervalue/ https://processwire.com/talk/topic/3145-multiple-views-for-templates/?pag…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche
https://processwire.com/talk/topic/13958-help-understanding-render-and-rendervalue/
https://processwire.com/talk/topic/3145-multiple-views-for-templates/?page=2#comment-32876

Auf den ersten Blick sehr verwirrend und nicht besonders gut dokumentiert sind die Render Funktionen in ProcessWire. Dazu kommen diverse shortcuts die den Überblick erschweren.

Sammlung

$page->render("some_field") is an alias for $page->renderField(),
If you provide a filename as a param, $page->render() will use that file to render given page
If you provide a filename (actual filename, not just something like "file") to $page->render() as the first param, you can provide an array as the second param, and the values stored in that array can then be accessed via $options.
wireRenderFile() renders a specific file without the need for a Page object

Beispiele

$page->render($filename); // $filename assumed in /site/templates/
$page->render($pathname); // $pathname is full path, but must resolve somewhere in web root
$page->render($options); // array of options and/or your own variables
$page->render(array('foo' => 'bar')); // same as above
$page->render($filename, $options); // specify filename and options/vars, etc.

Beispiel

If you made this render() call:

echo $page->render('myfile.php', array('foo' => 'bar')); 

myfile.php could access the 'foo' variable like this:

echo $options['foo']; // outputs "bar"

PageStack

$options['pageStack']. That is an array containing a stack of pages that called render().