Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
LouisGac
committed
Jan 10, 2017
1 parent
adfc166
commit 4b27d8b
Showing
1 changed file
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,49 @@ | ||
<?php | ||
/** | ||
* This extension is needed to add complex functions to twig, needing specific process (like accessing config datas). | ||
* Most of the calls to internal functions don't need to be set here, but can be directly added to the internal config file. | ||
* For example, the calls to encode, gT and eT don't need any extra parameters or process, so they are added as filter in the congif/internal.php: | ||
* | ||
* 'filters' => array( | ||
* 'jencode' => 'CJSON::encode', | ||
* 't' => 'eT', | ||
* 'gT' => 'gT', | ||
* ), | ||
* | ||
* So you only add functions here when they need a specific process while called via Twig. | ||
* To add an advanced function to twig. | ||
* | ||
* 1. Add it here as a static public function | ||
* eg: | ||
* static public function foo($bar) | ||
* { | ||
* return procces($bar); | ||
* } | ||
* | ||
* 2. Add it in config/internal.php as a function, and as an allowed function in the sandbox | ||
* eg: | ||
* twigRenderer' => array( | ||
* ... | ||
* 'functions' => array( | ||
* ... | ||
* 'foo' => 'LS_Twig_Extension::foo', | ||
* ...), | ||
* ... | ||
* 'sandboxConfig' => array( | ||
* ... | ||
* 'functions' => array('include', ..., 'foo') | ||
* ), | ||
* | ||
* Now you access this function in any twig file via: {{ foo($bar) }}, it will show the result of process($bar). | ||
* If LS_Twig_Extension::foo() returns some HTML, by default the HTML will be escaped and shows as text. | ||
* To get the pure HTML, just do: {{ foo($bar) | raw }} | ||
*/ | ||
|
||
|
||
class LS_Twig_Extension extends Twig_Extension | ||
{ | ||
|
||
static public function registerPublicCssFile($value) | ||
{ | ||
Yii::app()->getClientScript()->registerCssFile(Yii::app()->getConfig('publicstyleurl') . $value); | ||
App()->getClientScript()->registerCssFile(App()->getConfig('publicstyleurl') . $value); | ||
} | ||
} |