PHP Luminova: Template Rendering Configuration
Select a template engine and configure layout, isolation, and template directories.
The Template Configuration in Luminova allows you to choose and customize your template rendering engine: PHP, Twig, or Smarty. You can enable template isolation, turn on the default layout system, control how view options are named, and set the directories used by Smarty for compiled templates and configuration. For more information see View Rendering documentation.
Class Definition
- Full namespace:
App\Config\Template - File path:
/app/Config/Template.php - This class is final.
Properties
Note:Do not change the visibility of these properties nor the declaration types.
templateEngine
The template engine used to render application views.
public string $templateEngine = 'default';Available Template Engines
| Value | Template extension | Configuration |
|---|---|---|
default | .php | None required |
smarty | .tpl | /app/Config/Templates/Smarty/Extensions.php |
twig | .twig | /app/Config/Templates/Twig/Extensions.php |
The value is case insensitive. Any other value throws a RuntimeException when a view is rendered.
The extension is optional when you call view(), so view('home') and view('home.twig') resolve to the same template.
To use Smarty or Twig you first need to install the library, then register any classes, constants, functions or filters in the matching extensions file.
Smarty: Install via Composer.
composer require smarty/smarty:^5.7Twig: Install via Composer.
composer require "twig/twig:^3.0"Note:Both Smarty and Twig templates use
{{and}}as delimiters,and escapes HTML output automatically.
To learn more about Luminova Smarty or Twig extensions see documentation.
templateIsolation
Controls whether templates run in isolation.
When isolation is enabled, the template can no longer use $this to access template options or the view's public properties and methods. This protects the application and view object and forces the template to use a safer, limited interface.
Instead of:
<?= $this->optionName; ?>
<?= $this->app->appMethod(); ?>you must use:
<?= $self->optionName; ?>
<?= $self->app->appMethod(); ?>The $self object exposes only the options, exported objects, and view methods meant for the template. It also gives access to $self->app, $self->view, and $self->layout.
public bool $templateIsolation = false;To make a service available inside an isolated template, export it from the controller class with $this->tpl->export(...).
// In your application class
$this->tpl->export(new Session(), 'session');<?= $this->session->isOnline() ? 'Welcome back' : 'Please log in'; ?>
// In Isolation Mode
<?= $self->session->isOnline() ? 'Welcome back' : 'Please log in'; ?>Note:The
$selfvariable is reserved. If a template reassigns it, rendering fails with aRuntimeException.
Note:This setting has no effect when using Smarty or Twig. Those engines already isolate variables in their own way.To access the application or view object in those engines, use
{{ self.app }}in Twig and{{ $self->app }}in Smarty.
enablePhpTemplateLayout
Enable or disable the default PHP template layout object.
When enabled (true) and $templateEngine is set to default, you can use the built-in layout system for template inheritance. This allows you to extend parts of the layout easily, for example:
public bool $enablePhpTemplateLayout = false;Example:
$tpl = $this->layout->template('/layouts/scaffolding'); ?>
<?= $tpl->extend('head'); ?>
<?= $tpl->extend('section'); ?>
<?= $tpl->extend('footer'); ?>When template isolation is enabled, use $self->layout instead of $this->layout.
Note:When disabled (
false), the layout object isNULL. It is alsoNULLwhen$templateEngineissmartyortwig.To use layouts in that case, you must set them up manually.
See PHP Layout Composition documentation.
variablePrefixing
Controls whether options passed from a controller to a template are prefixed with an underscore _.
This property controls how you access the template options:
true→ Options use the_prefix (e.g.,$this->_optionNameor$self->_optionName).false→ No prefix is added (e.g.,$this->optionNameor$self->optionName).null→ Options are not exposed as properties. They are passed as a raw array (e.g.,$options['optionName']).
public ?bool $variablePrefixing = true;When prefixing is enabled, the unprefixed form also resolves, so $this->title and $this->_title return the same value. Hyphens in option names are converted to underscores, and each name must be a valid PHP variable name. An option can't reuse the alias of an exported object.
Built-in options
The view adds these options to every template.
| Option | Description |
|---|---|
href | Relative path to the public root. |
asset | Relative path to the assets/ directory. |
active | The name of the template being rendered. |
tplType | The template content type, such as html, json etc... |
title | Page title generated from the template name. Pass title to override it. |
subtitle | Same as title without the application name suffix. Pass subtitle to override it. |
noCache | Boolean you can pass to exclude the template from view caching. Defaults to false. |
The names href, self, asset, active and tplType are reserved, with or without the prefix. Passing any of them as an option throws a RuntimeException.
Note:This must be set before building your application.Changing it later will break template option recognition.
compileFolder
Directory used for compiled template files.
public string $compileFolder = 'writeable/compile/';The path is relative to the application root, without a leading slash. Currently only Smarty uses it, compiling templates into writeable/compile/smarty. Twig does not write compiled templates to this directory.
configFolder
Directory for template engine configuration files.
public string $configFolder = 'writeable/config/';The path is relative to the application root, without a leading slash. Currently only Smarty uses it, reading from writeable/config/smarty. Twig does not use this directory.