Templating¶
All templates and partials used by slCMS can be overridden, by simply
copying them directly into the webcontents
folder and altering them.
slCMS uses Mustache as its template engine. Template tags are contained in
curly braces ({}
), an extended list of the available tags can be found
below.
Templates¶
slCMS uses the following template files:
default
five_images
gallery
image-left-floating
no_text
two_to_four_images
wide_first
Template choosing is one of the core functionalities of slCMS. The template
selection happens in the method \slcms\Renderer::selectTemplate()
in the
file /src/Renderer.php
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | <?php declare(strict_types=1);
namespace slcms;
/**
* Class Renderer
*
* decides which template will be used and triggers the renderer to render the content to the output
*
* @package slcms
* @author Michael Ochmann <ochmannm@hochschule-trier.de>
* @since 0.0.1
*/
class Renderer {
private $template;
private $engine;
private $context;
public function __construct(models\Page &$context) {
$this->template = "default";
$this->context = $context;
$this->engine = TemplateEngine::Instance();
}
// choose a template and use it
public function render() : void {
$this->selectTemplate();
$template = $this->engine->loadTemplate($this->template);
echo $template->render($this->context);
}
// selecting a template depending on context
private function selectTemplate() : void {
if ($this->context->textsCount() > 100 && $this->context->imagesCount() === 0)
$this->template = "strangeTemplate";
elseif ($this->context->imagesCount() === 5){
if ($this->context->maxImageRatio() >= 0.0 && $this->context->maxImageRatio() <= 1.5){
$this->template = "five_images";
}
else {
$this->template = "wide_first";
}
}
elseif ($this->context->imagesCount() > 5)
$this->template = "gallery";
elseif ($this->context->imagesCount() > 1)
$this->template = "two_to_four_images";
elseif ($this->context->imagesCount() === 1 && $this->context->maxImageRatio() >= 0.0 && $this->context->maxImageRatio() <= 1.5) {
if ($this->context->textsCount() > 0){
$this->template = "image-left-floating";
}
else {
$this->template = "no_text";
}
}
//echo $this->template;
}
}
|
This functionality can be extended or altered via Plugins.