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 \BlackFox\Engine $this */ ?>
<!DOCTYPE html>
	<?= $this->GetHeader() ?>
	<title><?= $this->TITLE ?></title>
<h1><?= $this->TITLE ?></h1>
<?= $this->CONTENT ?>
page content generated in a requested file located in the virtual root
page title
path to the template folder relative to the server root
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:

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

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

Ask question