slick / template
Template component for Slick Framework
Installs: 3 958
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=8.0
- twig/twig: ^2.15.0|3.x-dev
Requires (Dev)
- behat/behat: 4.x-dev
- phpspec/phpspec: ^8.0@dev
- squizlabs/php_codesniffer: 4.0.x-dev
This package is auto-updated.
Last update: 2024-04-22 20:10:46 UTC
README
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.
Install
Via Composer
$ composer require slick/template
Usage
Configure template system
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.
Create you Twig templates
Lets create a sample index.html.twig
file in the folder that was
previously configured.
<h1>{{ post.title }}</h1> <p>{{ post.teaser|nl2br }}</p>
Note
All documentation and API for twig can be accessed in the Twig project home page
Use the template
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>
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email slick.framework@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.