Skip to main content
Version: Fegg 5.x (next)

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​

NameData typeDefaultRemarks
$templatestringTemplate name relative to the template root, without .tpl

Template variables​

VariableContent
$page$this->page of the controller: the page data
$siteSite information: site/config/site_info.php (loaded by the base controller) plus values set with setSiteinfo
$inRequest parameters, $_GET and $_POST ($this->in()). Not escaped: always output them with the default escaping
$configLoaded config files ($this->config)
$sessionSession 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
$cookieCookie data
$classNameController class name without namespace (News)
$languageCodeCurrent language code
$defineUser-defined PHP constants
$hiddenForTemplateValues 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().