ProcessWire - Rendering Funktionen: Unterschied zwischen den Versionen

Aus Wikizone
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: „In den Template Strategiene sind einige Methoden beschrieben wie man Seiten in ProcessWire rendern kann. PW stellt aber auch einige Funktionen bereit, mit dene…“)
 
Zeile 9: Zeile 9:
 
== Snippets ==
 
== Snippets ==
 
  $content .= $files->render('teasers', ['items' => $pages->find("template=article")]);
 
  $content .= $files->render('teasers', ['items' => $pages->find("template=article")]);
 +
=== Pass global vars ===
 +
You can pass variable via render like:
 +
 +
echo $pages->get($child->id)->render(array('mobile' => $mobile));
  
 
=== Check if File is called directly or via wireRenderFile ===
 
=== Check if File is called directly or via wireRenderFile ===
 +
https://processwire.com/talk/topic/20915-wirerenderfile-question-about-page/
 
Is there a way to check in my included template file if this child page is called directly, or whether it has been included from somewhere else? A simple check, so I can use the template in both scenarios (stand-alone view for just this page, or in cases I use wireRenderFile somewhere else). Right now I am passing the child page's ID like this:
 
Is there a way to check in my included template file if this child page is called directly, or whether it has been included from somewhere else? A simple check, so I can use the template in both scenarios (stand-alone view for just this page, or in cases I use wireRenderFile somewhere else). Right now I am passing the child page's ID like this:
  

Version vom 13. Februar 2020, 11:17 Uhr

In den Template Strategiene sind einige Methoden beschrieben wie man Seiten in ProcessWire rendern kann. PW stellt aber auch einige Funktionen bereit, mit denen man Dateien oder Seiten direkt rendern kann. Diese arbeiten auch gut mit dem WireCache zusammen. So kann man Teile der Ausgabe rendern und gleich Cachen.

Links

Functions

$files->render $page->render

Snippets

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

Pass global vars

You can pass variable via render like:

echo $pages->get($child->id)->render(array('mobile' => $mobile));

Check if File is called directly or via wireRenderFile

https://processwire.com/talk/topic/20915-wirerenderfile-question-about-page/

Is there a way to check in my included template file if this child page is called directly, or whether it has been included from somewhere else? A simple check, so I can use the template in both scenarios (stand-alone view for just this page, or in cases I use wireRenderFile somewhere else). Right now I am passing the child page's ID like this:

wireRenderFile('my_template', array('pid' => $child->id)); And in my_template, to access it's own page fields, etc. I use

$thisPage = pages()->get($pid);
$myField = $thisPage->foo; // etc.

Is that the way to go, or do I overlook something obvious?

d'oh of course, it's as simple as:

if(isset($pid)) {
   $thisPage = pages()->get($pid); // we get called with wireRenderFile
} else {
   $thisPage = $page; // business as usual
}