Skip to content

caffeina-core/twig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Core – Twig View

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>