LS_Twig_Extension

Extends\Twig_Extension

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:

  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 }}

package

Default

Methods

assetPublish

assetPublish(string $sRessource)
static

Arguments

$sRessource

string

Checks for a permission on render

checkPermission(String $permission,String $permissionGrade,Integer|NULL $iSurveyId = null): Boolean
static

Arguments

$permission

String

$permissionGrade

String

$iSurveyId

Integer|NULL

(default null)

Response

Boolean

createAbsoluteUrl

createAbsoluteUrl( $url, $params = array())
static

Arguments

$url

$params

createUrl

createUrl( $url, $params = array())
static

Arguments

$url

$params

darkencss

darkencss( $cssColor, $grade = 10, $alpha = 1)
static

Arguments

$cssColor

$grade

$alpha

get flat and ellipsize string

ellipsizeString(string $string,integer $maxlength,float $position = 1,string $ellipsis = '…'): string
static

Arguments

$string

string

to ellipsize

$maxlength

integer

of the final string

$position

float

of the ellipsis in string (between 0 and 1)

$ellipsis

string

string to shown in place of removed part

Response

string

flat and ellipsize text, for template compatibility

flatEllipsizeText(string $sString,boolean $bFlat = true,integer $iAbbreviated,string $sEllipsis = '...',integer $fPosition = 1): string
static
deprecated

(4.0)

Arguments

$sString

string

:the string

$bFlat

boolean

: flattenText or not : completely flat (not like flattenText from common_helper)

$iAbbreviated

integer

: max string text (if true : allways flat), 0 or false : don't abbreviated

$sEllipsis

string

if abbreviated : the char to put at end (or middle)

$fPosition

integer

if abbreviated position to split (in % : 0 to 1)

Response

string

Get html text and remove whole not clean string

flatString(string $string,boolean $encode = false): string
static

Arguments

$string

string

to flatten

$encode

boolean

html entities

Response

string

Retreive the question classes for a given question id Use in survey template question.twig file.

getAllQuestionClasses(integer $iQid): string
static

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).

Arguments

$iQid

integer

the question id

Response

string

the classes

Retreive all the previous answers from a given token To use it: {% set aResponses = getAllTokenAnswers(aSurveyInfo.sid) %} {{ dump(aResponses) }}

getAllTokenAnswers( $iSurveyID)
static

Of course, the survey must use token. If you want to show it after completion, the you must turn on public statistics

Arguments

$iSurveyID

getConfig

getConfig( $item)
static

Arguments

$item

Get the parsed output of the expression manger for a specific string

getExpressionManagerOutput(String $sInString): String
static

Arguments

$sInString

String

Response

String

getParam

getParam( $sName, $sDefaultValue = null)
static

Arguments

$sName

$sDefaultValue

getPosition

getPosition( $position): string
static

Arguments

$position

Response

string

getPost

getPost( $sName, $sDefaultValue = null)
static

Arguments

$sName

$sDefaultValue

getQuery

getQuery( $sName, $sDefaultValue = null)
static

Arguments

$sName

$sDefaultValue

getTemplateForRessource

getTemplateForRessource(string $sRessource)
static

Arguments

$sRessource

string

Get the textcontrol widget output for a specific string

getTextDisplayWidget(String $sInString, $name): String
static

Arguments

$sInString

String

$name

Response

String

image

image( $sImagePath, $alt = '', $htmlOptions = array()): string
static
var

string the image path relative to the template root

string the alternative text display

array additional HTML attribute

Arguments

$sImagePath

$alt

$htmlOptions

Response

string

imageSrc

imageSrc( $sImagePath, $default = false): string|false
static
var

string the image path relative to the template root

string|false an alternative image if the provided one cant be found

Arguments

$sImagePath

$default

Response

string|false

Check if a needle is in a multidimensional array

in_multiarray(mixed $needle,array $haystack,boolean $strict = false)

Arguments

$needle

mixed

The searched value.

$haystack

array

The array.

$strict

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.

Convert a json object to a PHP array (so no troubles with object method in sandbox)

json_decode(string $json,boolean $assoc = true): array
static

Arguments

$json

string

$assoc

boolean

return sub object as array too

Response

array

lightencss

lightencss( $cssColor, $grade = 10, $alpha = 1)
static

Arguments

$cssColor

$grade

$alpha

listCoreScripts

listCoreScripts()
static

listScriptFiles

listScriptFiles()
static

Process any string with current page

processString( $string,boolean $static = false,integer $numRecursionLevels = 3,array $aReplacement = array()): string
static

Arguments

$string

$static

boolean

return static string (or not)

$numRecursionLevels

integer

recursion (max) level to do

$aReplacement

array

replacement out of EM

Response

string

registerCssFile

registerCssFile( $path)
static

Arguments

$path

Publish a script file from general script directory, using or not the asset manager (depending on configuration) In any twig file, you can register a general script file doing: {{ registerGeneralScript($sGeneralScriptFileName) }}

registerGeneralScript(string $sGeneralScriptFileName,string $position = null,array $htmlOptions = array())
static

Arguments

$sGeneralScriptFileName

string

name of the script file to publish in general script directory (it should contains the subdirectories)

$position

string

$htmlOptions

array

registerPackage

registerPackage( $name)
static

Arguments

$name

Publish a css file from public style directory, using or not the asset manager (depending on configuration) In any twig file, you can register a public css file doing: {{ registerPublicCssFile($sPublicCssFileName) }}

registerPublicCssFile(string $sPublicCssFileName)
static

Arguments

$sPublicCssFileName

string

name of the CSS file to publish in public style directory

Publish a script In any twig file, you can register a script doing: {{ registerScript($sId, $sScript) }}

registerScript( $id, $script, $position = null,array $htmlOptions = array())
static

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()

Arguments

$id

$script

$position

$htmlOptions

array

registerScriptFile

registerScriptFile( $path, $position = null)
static

Arguments

$path

$position

Publish a css file from template directory, using or not the asset manager (depending on configuration) In any twig file, you can register a template css file doing: {{ registerTemplateCssFile($sTemplateCssFileName) }}

registerTemplateCssFile(string $sTemplateCssFileName)
static

Arguments

$sTemplateCssFileName

string

name of the CSS file to publish in template directory (it should contains the subdirectories)

Publish a script file from template directory, using or not the asset manager (depending on configuration) In any twig file, you can register a template script file doing: {{ registerTemplateScript($sTemplateScriptFileName) }}

registerTemplateScript(string $sTemplateScriptFileName,string $position = null,array $htmlOptions = array())
static

Arguments

$sTemplateScriptFileName

string

name of the script file to publish in general script directory (it should contains the subdirectories)

$position

string

$htmlOptions

array

renderCaptcha

renderCaptcha()
static

since count with a noncountable element is throwing a warning in latest php versions we have to be sure not to kill rendering by a wrong variable

safecount(mixed $element): void
static

Arguments

$element

mixed

templateResourceUrl

templateResourceUrl( $resourcePath, $default = false): string|false
static
var

string : the needed resource

string : the default resource if needed resssource didn't exist

Arguments

$resourcePath

$default

Response

string|false

unregisterPackage

unregisterPackage(string $name)
static

Arguments

$name

string

unregisterScriptFile

unregisterScriptFile(string $name)
static

Arguments

$name

string

Unregister all packages/script files for AJAX rendering

unregisterScriptForAjax()
static