avris / micrus-twig
Twig bridge for the Micrus framework
Installs: 435
Dependents: 8
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/avris/micrus-twig
Requires
- avris/micrus: ^4.0
- twig/twig: ^2.4
README
This is a module for Micrus framework that allows you to integrate it with Twig template engine.
Installation
Run:
composer require avris/micrus-twig
Then register the module in your App\App:registerModules:
yield new \Avris\Micrus\Twig\TwigModule;
Usage
Just put your *.twig templates in the /templates directory and render them in your controller.
If you don't specify an extension, .html.twig will be assumed:
$this->render('Post/show', ['post' => $post]); // will render Post/show.html.twig
A twig global app is added, which gives you access to:
app.user(nullif not logged in)app.flashBagapp.requestapp.routeMatchapp.session
Also some helper functions are provided:
route('route', {params: value})routeExists('route')asset('asset.css')isGranted('ROLE_ADMIN')canAccess('check', object)dump(object)
Extending Twig
To create Twig extension, please follow its documentation.
Any class extending Twig\Extension\AbstractExtension in an autoloaded directory
will be automatically registered as a Twig extension.
To do it manually, just declare it with a tag twigExtension:
App\Service\MyTwigExtension:
tags: [twigExtension]
Copyright
- Author: Andrzej Prusinowski (Avris.it)
- Licence: MIT