Theme editor - Available Twig functions: Difference between revisions
From LimeSurvey Manual
DenisChenu (talk | contribs) (Text update and management) |
DenisChenu (talk | contribs) m (→image) |
||
(17 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
= | == PHP included functions == | ||
* [http://php.net/array-flip array_flip] | * [http://php.net/array-flip array_flip] | ||
Line 12: | Line 12: | ||
* [http://php.net/sprintf sprintf] | * [http://php.net/sprintf sprintf] | ||
= Specific function for LimeSurvey = | == Specific function for LimeSurvey == | ||
== Text update and management == | === Text update and management === | ||
=== flatString === | ==== flatString ==== | ||
Get html text and remove whole not clean string. | Get html text and remove whole not clean string. | ||
Parameters are | Parameters are | ||
Line 22: | Line 22: | ||
* a boolean encode html entities (default to false) | * a boolean encode html entities (default to false) | ||
=== ellipsizeString === | ==== ellipsizeString ==== | ||
Get a flat and ellipsize string. | Get a flat and ellipsize string. | ||
Parameters are | Parameters are | ||
Line 30: | Line 30: | ||
* a string ellipsis string to shown in place of removed part, default to … | * a string ellipsis string to shown in place of removed part, default to … | ||
=== processString === | ==== processString ==== | ||
Process | Process ExpressionScript with any string with current page information, return a string. | ||
Parameters are | Parameters are | ||
* the string to be processed | * the string to be processed | ||
* a boolean : return static string (or not), default to no. | * a boolean : return static string (or not), default to no. | ||
* an integer : recursion (max) level to do, default to 3 | * an integer : recursion (max) level to do, default to 3 | ||
* an array of string: replacement out of current expression know vars. The | * an array of string: replacement out of current expression know vars. The key is the value to be replaced, the value is the replacement. | ||
== | === Image and file source === | ||
=== | ==== image ==== | ||
Create a image tag, parameters are | |||
* The source of image, realted to theme directory (./img/logo.png for example) | |||
* alt attribute | |||
* array of extra html function (as array for twig : <code>{"class": "logo img-fluid"}</code>) | |||
=== getConfig === | ==== imageSrc ==== | ||
Create the dynamic source to an image inside theme, using parent theme if image are not found in current one. Retuen an image only. | |||
* Image path relative to theme directory | |||
* default value if not found | |||
==== templateResourceUrl ==== | |||
Create the dynamic source of a file, using parent theme if file are not found in current one. | |||
* file path relative to theme directory | |||
* default value if not found | |||
=== Language management === | |||
==== gT ==== | |||
==== ngT ==== | |||
=== Get information === | |||
==== getConfig ==== | |||
Get the current config part for this instance of LimeSurvey for the parameter. Return the existing config, false if not set. | Get the current config part for this instance of LimeSurvey for the parameter. Return the existing config, false if not set. | ||
Line 53: | Line 77: | ||
Get the current $_POST value for the parameter. Return the existing $_POST, null if not set. | Get the current $_POST value for the parameter. Return the existing $_POST, null if not set. | ||
=== getQuery === | ==== getQuery ==== | ||
Get the current $_GET value for the parameter. Return the existing $ | Get the current $_GET value for the parameter. Return the existing $_GET, null if not set. | ||
=== getParam === | ==== getParam ==== | ||
Get the current $_PARAM value for the parameter. | Get the current $_PARAM value for the parameter. Returns the existing $_PARAM, null if not set. | ||
== Script and css management == | === Script and css management === | ||
* registerPublicCssFile | * registerPublicCssFile | ||
Line 75: | Line 99: | ||
* listScriptFiles | * listScriptFiles | ||
== Others | === Others === | ||
=== getAllTokenAnswers === | ==== getAllTokenAnswers ==== | ||
= Adding a function = | == Adding a function == | ||
You can add any PHP existing function easily in your config.php file. This is done adding the function in twigRenderer. | === By updating config.php === | ||
You can add any PHP existing function easily in your config.php file. This is done by adding the function in twigRenderer. | |||
<syntaxhighlight lang="php" enclose="pre"> | <syntaxhighlight lang="php" enclose="pre"> | ||
Line 101: | Line 120: | ||
), | ), | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== By extension === | |||
See [https://github.com/LimeSurvey/LimeSurvey/tree/master/upload/twig/extensions Custom Twig Extension for LimeSurvey] | |||
[[Category:Theme]] | |||
[[Category:Twig]] | |||
[[Category:Development]] |
Latest revision as of 17:22, 25 October 2023
PHP included functions
Specific function for LimeSurvey
Text update and management
flatString
Get html text and remove whole not clean string. Parameters are
- the string to flatten
- a boolean encode html entities (default to false)
ellipsizeString
Get a flat and ellipsize string. Parameters are
- the string to ellipsize
- an integer max length of the final string
- a float $position of the ellipsis in string (between 0 and 1), default to 1 mean the string is ellipsize at end.
- a string ellipsis string to shown in place of removed part, default to …
processString
Process ExpressionScript with any string with current page information, return a string. Parameters are
- the string to be processed
- a boolean : return static string (or not), default to no.
- an integer : recursion (max) level to do, default to 3
- an array of string: replacement out of current expression know vars. The key is the value to be replaced, the value is the replacement.
Image and file source
image
Create a image tag, parameters are
- The source of image, realted to theme directory (./img/logo.png for example)
- alt attribute
- array of extra html function (as array for twig :
{"class": "logo img-fluid"}
)
imageSrc
Create the dynamic source to an image inside theme, using parent theme if image are not found in current one. Retuen an image only.
- Image path relative to theme directory
- default value if not found
templateResourceUrl
Create the dynamic source of a file, using parent theme if file are not found in current one.
- file path relative to theme directory
- default value if not found
Language management
gT
ngT
Get information
getConfig
Get the current config part for this instance of LimeSurvey for the parameter. Return the existing config, false if not set.
getPost
Get the current $_POST value for the parameter. Return the existing $_POST, null if not set.
getQuery
Get the current $_GET value for the parameter. Return the existing $_GET, null if not set.
getParam
Get the current $_PARAM value for the parameter. Returns the existing $_PARAM, null if not set.
Script and css management
- registerPublicCssFile
- registerTemplateCssFile
- registerGeneralScript
- registerTemplateScript
- registerScript
- registerPackage
- unregisterPackage
- registerCssFile
- registerScriptFile
- unregisterScriptFile
- unregisterScriptForAjax
- listCoreScripts
- listScriptFiles
Others
getAllTokenAnswers
Adding a function
By updating config.php
You can add any PHP existing function easily in your config.php file. This is done by adding the function in twigRenderer.
'twigRenderer' => array(
'functions' => array(
'strlen' => 'strlen',
),
'sandboxConfig' => array(
'functions' => array(
'strlen',
),
),
),