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:
A template's wrapper must contain a call to print the page title, headings, and content:
<?php /** @var \BlackFox\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
<?php /** @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.
return [ 'TEMPLATE' => 'another_template', 'WRAPPER' => 'another_wrapper', ];
/** @var \BlackFox\Engine $this */ $this->TEMPLATE = 'another_template'; $this->WRAPPER = 'another_wrapper';
Error handling when generating the page
The
<?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