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 filters 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:
Add it here as a static public function eg: static public function foo($bar) { return procces($bar); }
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 }}
package | Default |
---|
assetPublish(string $sRessource)
string
checkPermission(String $permission,String $permissionGrade,Integer|NULL $iSurveyId = null): Boolean
String
String
Integer|NULL
(default null)
Boolean
createAbsoluteUrl( $url, $params = array())
createUrl( $url, $params = array())
darkencss( $cssColor, $grade = 10, $alpha = 1)
ellipsizeString(string $string,integer $maxlength,float $position = 1,string $ellipsis = '…'): string
string
to ellipsize
integer
of the final string
float
of the ellipsis in string (between 0 and 1)
string
string to shown in place of removed part
string
flatEllipsizeText(string $sString,boolean $bFlat = true,integer $iAbbreviated,string $sEllipsis = '...',integer $fPosition = 1): string
deprecated | (4.0) |
---|
string
:the string
boolean
: flattenText or not : completely flat (not like flattenText from common_helper)
integer
: max string text (if true : always flat), 0 or false : don't abbreviated
string
if abbreviated : the char to put at end (or middle)
integer
if abbreviated position to split (in % : 0 to 1)
string
flatString(string $string,boolean $encode = false): string
string
to flatten
boolean
html entities
string
getAllQuestionClasses(integer $iQid): string
TODO: we'd rather provide a oQuestion object to the twig view with a method getAllQuestion(). But for now, this public static function respect the old way of doing
deprecated | must be removed when allow to broke template. Since it was in 3.0 , it was in API (and question.twig are surely be updated). |
---|
integer
the question id
string
the classes
getAllTokenAnswers( $iSurveyID)
Of course, the survey must use token. If you want to show it after completion, the you must turn on public statistics
getConfig( $item)
getExpressionManagerOutput(String $sInString): String
String
String
getFilters(): array<mixed,\Twig\TwigFilter>
getFunctions(): array<mixed,\Twig\TwigFunction>
getGlobals(): array
deprecated | since 1.23 (to be removed in 2.0), implement \Twig_Extension_GlobalsInterface instead |
---|---|
array
An array of global variables
getGoogleAnalyticsTrackingUrl(integer $surveyId,string $trackUrlPageName = ''): string
integer
string
Specific page name to include in the tracking url. If it's empty, we will try to infer it from the context.
string
The tracking URL as "
getLanguageRTL( $sLanguageCode)
getName(): string
deprecated | since 1.26 (to be removed in 2.0), not used anymore internally |
---|---|
string
The extension name
getNodeVisitors(): array<mixed,\Twig\NodeVisitor\NodeVisitorInterface>
getOperators(): \Twig\Extension\array<array>
\Twig\Extension\array
First array of unary operators, second array of binary operators
getParam( $sName, $sDefaultValue = null)
getPosition( $position): string
string
getPost( $sName, $sDefaultValue = null)
getQuery( $sName, $sDefaultValue = null)
getTemplateForRessource(string $sRessource)
string
getTests(): array<mixed,\Twig\TwigTest>
getTextDisplayWidget(String $sInString, $name): String
String
String
getTokenParsers(): array<mixed,\Twig\TokenParser\TokenParserInterface>
image( $sImagePath, $alt = '', $htmlOptions = array()): string
var | string the image path relative to the template root string the alternative text display array additional HTML attribute |
---|---|
string
imageSrc( $sImagePath, $default = false): string|false
var | string the image path relative to the template root string|false an alternative image if the provided one cant be found |
---|---|
string|false
in_multiarray(mixed $needle,array $haystack,boolean $strict = false)
mixed
The searched value.
array
The array.
boolean
If the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack.
initRuntime(\Twig\Environment $environment)
This is where you can load some file that contains filter functions for instance.
deprecated | since 1.23 (to be removed in 2.0), implement \Twig_Extension_InitRuntimeInterface instead |
---|---|
\Twig\Environment
json_decode(string $json,boolean $assoc = true): array
string
boolean
return sub object as array too
array
lightencss( $cssColor, $grade = 10, $alpha = 1)
listCoreScripts()
listScriptFiles()
processString( $string,boolean $static = false,integer $numRecursionLevels = 3,array $aReplacement = array()): string
boolean
return static string (or not)
integer
recursion (max) level to do
array
replacement out of EM
string
registerCssFile( $path)
registerGeneralScript(string $sGeneralScriptFileName,string $position = null,array $htmlOptions = array())
string
name of the script file to publish in general script directory (it should contains the subdirectories)
string
array
registerPackage( $name)
registerPublicCssFile(string $sPublicCssFileName)
string
name of the CSS file to publish in public style directory
registerScript( $id, $script, $position = null,array $htmlOptions = array())
NOTE: this function is not recursive, so don't use it to register a script located inside a theme folder, or inherited themes will be broken. NOTE! to register a script located inside a theme folder, registerTemplateScript()
array
registerScriptFile( $path, $position = null)
registerTemplateCssFile(string $sTemplateCssFileName)
string
name of the CSS file to publish in template directory (it should contains the subdirectories)
registerTemplateScript(string $sTemplateScriptFileName,string $position = null,array $htmlOptions = array())
string
name of the script file to publish in general script directory (it should contains the subdirectories)
string
array
renderCaptcha()
safecount(mixed $element): void
mixed
templateResourceUrl( $resourcePath, $default = false): string|false
var | string : the needed resource string : the default resource if needed resssource didn't exist |
---|---|
string|false
unregisterPackage(string $name)
string
unregisterScriptFile(string $name)
string
unregisterScriptForAjax()