Download the PHP package computator/php-template-library without Composer
On this page you can find all versions of the php package computator/php-template-library. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download computator/php-template-library
More information about computator/php-template-library
Files in computator/php-template-library
Package php-template-library
Short Description Templating library using native PHP syntax
License MIT
Informations about the package php-template-library
Overview
This library is a templating engine for PHP that uses native PHP syntax to increase template flexibility and reduce processing overhead.
Part of https://github.com/computator/php-framework-utils.
Code Coverage is available here.
Usage
Installation
The library is available on Packagist via composer, and is installable as computator/php-template-library or included in computator/framework-utils.
Method Overview
The primary engine interfaces are defined in the UserApi namespace.
UserApi/TemplateClient: Primary methods for utilizing the engine in templates.UserApi/ResolvedTemplateClient: Methods available on objects retrieved usingself::tpl()while rendering.Renderer.Rendererduring the render process.
Templates
Templates are executed with access to the methods defined in UserApi/ResolvedTemplateClient.
Using Short Open Tags, Alternative Control Structure Syntax, and leaving out the final semicolon in closing tags is encouraged to make templates more readable.
Template Types
There are several included template types:
Templates/File: Directly executes the named PHP file. (default)Templates/PHPString: Executes the provided literal string of PHP code.Templates/Text: Plain text (no execution).
Examples
These examples demonstrate the primary concepts of the library with a main, parent, and child template. Note that the templates can be modified to avoid referencing literal .php filenames by using an alternative TemplateResolver.
Multiple Child Blocks
main.php
parent.php
child.php
Primary Child Content
main.php
parent.php
child.php
Rendering
Rendering is controlled by creating a new instance of a UserApi/RenderClient.
The resolution of non-root template names to templates can be controlled by specifying an optional TemplateResolver. The default implementation passes the template name directly to the configured template class.