slick/template

Template component for Slick Framework

v2.0.0 2023-02-22 17:50 UTC

README

Latest Version on Packagist Software License Build Status Quality Score Total Downloads

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.