Theme editor - Available Twig functions
From LimeSurvey Manual
(Redirected from Theme:Available function)
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
Remember, by default SVG files are blacklisted for potential security issues. Before use inside your custom theme, you need to allow them inside the templates, by editing application config file.
image()
Returns the HTML code needed for an image tag. Parameters are:
- The source of image, relative to theme directory (img/logo.png for example)
- alt attribute, useful for better accessibility
- array of extra html function (as array for twig :
{"class": "logo img-fluid"}
)
Not useful if you want display a SVG image, they are rendered differently, not by <img />
tag.
imageSrc()
Returns the dynamic path to a theme's image, obtained in the cache. Looks for parent's theme image, when not found in current theme.
- Image path relative to theme directory (img/mylogo.png for example)
- default value if image file was not found (img/default-avatar.png for example)
Can be used to render SVG. For example: <svg><use src="{{ imageSrc('img/logo.svg') }}" ></use></svg>
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',
),
),
),