Twig bridge for the Micrus framework

v4.0.1 2018-04-02 20:49 UTC

This package is auto-updated.

Last update: 2024-05-29 03:44:40 UTC


This is a module for Micrus framework that allows you to integrate it with Twig template engine.



composer require avris/micrus-twig

Then register the module in your App\App:registerModules:

yield new \Avris\Micrus\Twig\TwigModule;


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 (null if not logged in)
  • app.flashBag
  • app.request
  • app.routeMatch
  • app.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:

  tags: [twigExtension]