Twig service for Caffeina Core Views

1.2.0 2016-03-31 15:11 UTC

README

Scrutinizer Code Quality Build Status Total Downloads Latest Stable Version Latest Unstable Version License

Twig bridge for Core View.

Installation

Install via composer:

$ composer require caffeina-core/twig -o

Twig

Twig documentation : http://twig.sensiolabs.org/documentation

Twig Core\View Extras

Adding a Twig Filter

View::addFilter('rot13',function($text){
  return str_rot13($text);
});
<li>test = {{ test|rot13 }}</li>

Outputs :

<li>test = grfg</li>

Adding global constants

View::addGlobals([
  'BASE_URL'     => '/site/',
  'ASSETS_URL'   => '/site/assets/',
]);
<script src="{{ ASSETS_URL }}js/main.js"></script>

Adding a Twig Function

View::addFunction('myFunction',function($a,$b,$c){
  return $a + $b + $c;
});
Value = <b>{{ myFunction(1,2,3) }}</b>

Outputs :

Value = <b>6</b>