avris/micrus-twig

Twig bridge for the Micrus framework

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

This package is auto-updated.

Last update: 2022-11-29 02:17:25 UTC


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 (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:

App\Service\MyTwigExtension:
  tags: [twigExtension]

Copyright