processwire / processwire-requests

ProcessWire feature requests.
39 stars 0 forks source link

Documentation addendum for api-vars access #526

Open pine3ree opened 2 weeks ago

pine3ree commented 2 weeks ago

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...