Slick Template is a simple wrapper to a template engine of your choice. It defines simple interfaces that allow you to create your own PHP template engines. It comes with Twig template engine implementation, a flexible, fast, and secure template engine for PHP.
This package is compliant with PSR-2 code standards and PSR-4 autoload standards. It also applies the semantic version 2.0.0 specification.
Via Composer
$ composer require slick/template
use Slick\Template\Template;
Template::addPath('/path/to/twig/files');
$twig = (new Template(['engine' => Template::ENGINE_TWIG])->initialize();
Basically you need to set the path (or paths) where your .twig
files
live and initialize the Twig template engine.
Lets create a sample index.html.twig
file in the folder that was
previously configured.
<h1>{{ post.title }}</h1>
<p>{{ post.teaser|nl2br }}</p>
All documentation and API for twig can be accessed in the Twig project home page
Now lets grab some data and create the HTML output using the twig template:
$data = [
'post' => (object) [
'title' => 'Sample blog post',
'teaser' => 'Sample teaser for the blog post.'
]
];
$html = $template->parse('index.html.twig')
->process($data);
Output:
<h1>Sample blog post\</h1>
<p>Sample teaser for the blog post.\</p>
Please see CHANGELOG for more information on what has changed recently.
$ composer test
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email slick.framework@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.