Application::fetchPage
Return a page rendered with the standard template variables as a string
Description
public string Application::fetchPage( string $template )
Collects the standard template variables (below), renders the template with Application::fetchTemplate and returns the result instead of outputting it. Application::displayPage uses it.
Use it when you need the page as a string: to post-process it, or as the body of a mail. Unlike displayPage(), it does not end the response. The security headers do not depend on which method you use (see Security).
Arguments
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $template | string | Template name relative to the template root, without .tpl |
Template variables
| Variable | Content |
|---|---|
$page | $this->page of the controller: the page data |
$site | Site information: site/config/site_info.php (loaded by the base controller) plus values set with setSiteinfo |
$in | Request parameters, $_GET and $_POST ($this->in()). Not escaped: always output them with the default escaping |
$config | Loaded config files ($this->config) |
$session | Session data, plus session_id and session_name while a session is active. Reading it does not start a session: without a session cookie it is empty |
$cookie | Cookie data |
$className | Controller class name without namespace (News) |
$languageCode | Current language code |
$define | User-defined PHP constants |
$hiddenForTemplate | Values set with setHidden, printed by the {{ hidden }} tag |
Example
htdocs/_fegg/site/controller/Foo.php
<?php
namespace Site\Controller;
defined('FEGG_CORE_DIR') || exit;
class Foo extends Controller
{
// URL: https://example.com/foo/bar/?get=param
public function bar()
{
$this->page['baz'] = 'qux';
echo $this->fetchPage('foo/bar');
}
}
htdocs/_fegg/site/template/foo/bar.tpl
Baz param : {{ $page.baz }}
$_GET[get] param : {{ $in.get }}
Controller name : {{ $className }}
Output
Baz param : qux
$_GET[get] param : param
Controller name : Foo
note
The site-wide Basic authentication (basic_auth_scope = 1) is checked before the controller runs, so it also protects actions that only call fetchPage().