processwire-requests icon indicating copy to clipboard operation
processwire-requests copied to clipboard

Documentation addendum for api-vars access

Open pine3ree opened this issue 1 year ago • 0 comments

Access api vars from templates using $this->{api-var-name}

Inside pw template files and all partials included using wireRenderFile($template, $vars) aka $files->render($template, $vars) $this refers to the TemplateFile instance, so we can access api-vars in the following way:

<?php namespace ProcessWire;

// Next line add autocompletion for $this
/** @var TemplateFile $this */

$this->page;
$this->files->render('view/layout.html.php', get_defined_vars());
// etc...

pine3ree avatar Jun 16 '24 17:06 pine3ree