Template and wrapper

A template — is a folder with php files, some of which are used as wrappers for generating a page. A wrapper — is a php file containing: header, echo of content, footer. The folder name is the template code (for example: bootstrap). The name of the php file without the extension is the template's wrapper code (default: wrapper). One template can contain multiple wrappers. In addition to executable files, the template may contain other static files for include (scripts, styles and images).

A template's wrapper must contain a call to print the page title, headings, and content:

<?php /** @var \System\Engine $this */ ?>
<!DOCTYPE html>
<html>
<head>
	= $this->GetHeader() ?>
	<title>= $this->TITLE ?></title>
</head>
<body>
<h1>= $this->TITLE ?></h1>
= $this->CONTENT ?>
</body>
</html>
$CONTENT
page content generated in a requested file located in the virtual root
$TITLE
page title
$TEMPLATE_PATH
path to the template folder relative to the server root
GetHeader()
dynamically connected scripts and styles

Scripts and styles that are present on all pages can be included in the usual way.
If in the process of generating the page content it is necessary to connect additional scripts and styles, use methods AddHeaderScript, AddHeaderStyle, AddHeaderString:

<?php
/** @var \System\Engine $this */
$this->AddHeaderScript($this->TEMPLATE_PATH . '/script.js');
$this->AddHeaderStyle($this->TEMPLATE_PATH . '/style.css');
$this->AddHeaderString('<meta .../>');

Management of template and wrapper

It is possible to dynamically redefine the template code and the wrapper code.

For the entire section in the file .section.php:
return [
	'TEMPLATE' => 'another_template',
	'WRAPPER'  => 'another_wrapper',
];

For a specific executable file:
/** @var \System\Engine $this */
$this->TEMPLATE = 'another_template';
$this->WRAPPER = 'another_wrapper';


Error handling when generating the page

The errors.php file at the root of the template is not a wrapper, it is used for generating content of the page that displays errors that occurred during the generation of the original page.

<?php /** @var \System\Engine $this */ ?>
<?php /** @var array $errors */ ?>
 foreach ($errors as $error): ?>
	<div class="alert alert-danger">= $error ?></div>
 endforeach; ?>

If desired, this engine behavior can be overridden by overriding the method ShowErrors of class Engine.

Ask question