ProcessWire - Render Funktionen

Aus Wikizone
Wechseln zu: Navigation, Suche

Hier eine Übersicht über verschiedene Möglichkeiten Files, Felder und Templates zu rendern.

Links

ProcessWire - Page Rendering Functions
ProcessWire - Rendering Funktionen
ProcessWire - Rendering Templates mit fields Ordner
https://processwire.com/blog/posts/processwire-3.0.7-expands-field-rendering-page-path-history-and-more/#theres-also-page-gt-rendervalue
https://processwire.com/api/ref/page/render-value/

Kleine ProcessWire Renderübersicht

Die häufigsten...

// $page->render
$page->render($filename); // $filename (including .php) assumed in /site/templates/
$page->render($pathname); // $pathname is full path, but must resolve somewhere in web root
$page->render($filename, $myArray); // $myArray can be accessed via $options in Template
$page->render($fieldname) // short for $page->renderField() IF parameter is a fieldname - then pw looks for template file in /fields

// renderValue usage
$mixed = $page->renderValue(mixed $value);
$mixed = $page->renderValue(mixed $value, string $file = '');

// Render a value using site/templates/fields/my-images.php custom output template
$images = $page->images;
echo $page->renderValue($images, 'my-images'); 

// In Template .../fields/children.php access $results as $value 
$results = $pages->find("body%=some text");
echo $page->renderValue($results, 'children'); 

//FILES 
// $files->renderUsage
$files->render('teasers', ['items' => $pages->find("template=article")]); // mostly for delayed output
wireRenderFile('my_template', array('pid' => $child->id)); // old version of $files->render
wireIncludeFile() // for direct output

//$page->render() is intended for rendering a specific page (optionally using a specific file)
//wireRenderFile() renders a specific file without the need for a Page object
$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.


$content .= $files->render('teasers', ['items' => $pages->find("template=article")]);

foreach ($pages->find("template=article") as $article) {
    $content .= $article->render('teaser.php');
}

Use Cases und Unterschiede

$page->render('some_field') 

does indeed call renderField(), but only if the given param is a field name. Take a look at PageRender for more details.

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.

It seems to me that you're trying to use $page->render() to something it's really not meant for: $page->render() is intended for rendering a specific page (optionally using a specific file), while wireRenderFile() renders a specific file without the need for a Page object. Those are two different use cases.