LSETwigViewRenderer

Extends\ETwigViewRenderer

Twig view renderer, LimeSurvey overload

Allow to run sandbox Configuration Provide different render methods for different context:

  • render() : for general use
  • renderQuestion() : to render a question. It checks if a question template view should be use, else core's view (used from qanda helper).
  • convertTwigToHtml() : to render a string without any file (used from replacement helper)

The only tricky point here is the path problematic (where should be searched the views to render?)

see

http://twig.sensiolabs.org/doc/2.x/api.html#loaders

author

Leonid Svyatov leonid@svyatov.ru

author

Alexander Makarov sam@rmcreative.ru

link

http://github.com/yiiext/twig-renderer

link

http://twig.sensiolabs.org

version 1.1.15
package

Default

Methods

Adds custom function or filter

_addCustom(string $classType,array $elements)
inherited
Throws
\CException

Arguments

$classType

string

'Function' or 'Filter'

$elements

array

Parameters of elements to add

Adds custom extensions

addExtensions(array $extensions)
inherited

Arguments

$extensions

array

@see self::$extensions

Adds custom filters

addFilters(array $filters)
inherited

Arguments

$filters

array

@see self::$filters

Adds custom functions

addFunctions(array $functions)
inherited

Arguments

$functions

array

@see self::$functions

Adds global objects or static classes

addGlobals(array $globals)
inherited

Arguments

$globals

array

@see self::$globals

Twig can look for twig path in different path. This function will add the path of the template and all its parents to the load path So if a twig file is inclueded, it will look in the local template directory and all its parents

addRecursiveTemplatesPath(\TemplateConfiguration $oTemplate,array<mixed,string> $extraPaths = array(),string|null $dirName = null)

Arguments

$oTemplate

\TemplateConfiguration

the template where to start

$extraPaths

array<mixed,string>

to be added before template, parent template plugin add and core views. Example : question template

$dirName

string|null

directory name to be added as extra directory inside template view

Adds custom user extensions

addUserExtensions(array $extensions)

Arguments

$extensions

array

@see self::$user_extensions

Convert a string containing twig tags to an HTML string.

convertTwigToHtml(string $sString,array $aData = array(),\TemplateConfiguration|null $oTemplate = null): string
Throws
\Throwable
\Twig_Error_Loader
\Twig_Error_Syntax

Arguments

$sString

string

The string of HTML/Twig to convert

$aData

array

Array containing the datas needed to render the view ($thissurvey)

$oTemplate

\TemplateConfiguration|null

Response

string

It can happen that user set incoherent values for options (like background is on, but no image file is selected) With some server configuration, it can lead to critical errors : empty values in image src or url() can block submition This function will check thoses cases. It can be used in the future for further checks

fixDataCoherence(array $aData): array

Arguments

$aData

array

Response

array

In the LS2.x code, some of the render logic was duplicated on different files (surveyRuntime, frontend_helper, etc) In LS3, we did a first cycle of refactorisation. Some logic common to the different files are for now here, in this function.

getAdditionalInfos( $aData,\TemplateConfiguration $oTemplate): 

TODO: move all the display logic to surveyRuntime so we don't need this function here

Arguments

$aData

$oTemplate

\TemplateConfiguration

Response

This is used to add paths in controller views.

getLoader(): \FileLoader

Response

\FileLoader

Get the final source file for current context Currently used in theme editor

getPathOfFile(string $twigView,\TemplateConfiguration $oTemplate = null,array<mixed,string> $extraPath = array(),string|null $dirName = null): string
Throws
\Exception

Arguments

$twigView

string

twigfile to be used (with twig extension)

$oTemplate

\TemplateConfiguration

$extraPath

array<mixed,string>

path to be added before plugins add and core views

$dirName

string|null

directory name to be added as extra directory inside template view

Response

string

complete filename to be used

Plugin event, should be replaced by Question Template

getPluginsData(string $sString,array $aData): array

Arguments

$sString

string

$aData

array

Response

array

Find which template should be used to render a given view

getTemplateForView(string $sView,\TemplateConfiguration $oRTemplate): \Template|boolean

Arguments

$sView

string

the view (layout) to render

$oRTemplate

\TemplateConfiguration

the template where the custom option page should be looked for

Response

\Template|boolean

Returns Twig object

getTwig(): \Twig_Environment
inherited

init

init()
inherited

This method is used to render question's subquestions and answer options pages .

renderAnswerOptions(string $sView,array $aData): string

It first checks if the question use a template (set in display attributes) If it is the case, it will use the views of that template, else, it will render the core view.

Throws
\CException
\Twig_Error_Loader
\Twig_Error_Syntax

Arguments

$sView

string

the view (layout) to render

$aData

array

the datas needed for the view rendering

Response

string

the generated html

Renders a view file.

renderFile(\CBaseController $context,string $sourceFile,mixed $data,boolean $return): mixed
inherited

This method is required by \IViewRenderer.

Arguments

$context

\CBaseController

the controller or widget who is rendering the view file.

$sourceFile

string

the view file path

$data

mixed

the data to be passed to the view

$return

boolean

whether the rendering result should be returned

Response

mixed

the rendering result, or null if the rendering result is not needed.

Render the survey page, with the headers, the css, and the script If LS would use the normal Yii render flow, this function would not be necessary In previous LS version, this logic was here: https://github.com/LimeSurvey/LimeSurvey/blob/700b20e2ae918550bfbf283f433f07622480978b/application/controllers/survey/index.php#L62-L71

renderHtmlPage(string $sHtml,\Template $oTemplate)

Arguments

$sHtml

string

The Html content of the page (it must not contain anymore any twig statement)

$oTemplate

\Template

The name of the template to use to register the packages

Render the option page of a template for the admin interface

renderOptionPage(\Template $oTemplate,array $renderArray = array()): string
Throws
\Throwable
\Twig_Error_Loader
\Twig_Error_Syntax

Arguments

$oTemplate

\Template

the template where the custom option page should be looked for

$renderArray

array

Array that will be passed to the options.twig as variables.

Response

string

get a twig file and return html produced

renderPartial(string $twigView,array $aData): string
todo

find a way to fix in beforeCloseHtml @see https://bugs.limesurvey.org/view.php?id=13889

Throws
\Twig_Error_Loader
\Twig_Error_Syntax

Arguments

$twigView

string

twigfile to be used (with twig extension)

$aData

array

to be used

Response

string

This method is called from qanda helper to render a question view file.

renderQuestion(string $sView,array $aData): string

It first checks if the question use a template (set in display attributes) If it is the case, it will use the views of that template, else, it will render the core view.

Throws
\CException
\Twig_Error_Loader
\Twig_Error_Syntax

Arguments

$sView

string

the view (layout) to render

$aData

array

the datas needed for the view rendering

Response

string

the generated html

Main method to render a question in the question editor preview.

renderTemplateForQuestionEditPreview(string $sLayout,array $aData,boolean $root = false,boolean $bReturn = false): mixed|string
Throws
\CException
\Throwable
\Twig_Error_Loader
\Twig_Error_Syntax
\WrongTemplateVersionException

Arguments

$sLayout

string

the name of the layout to render

$aData

array

the datas needed to fill the layout

$root

boolean

$bReturn

boolean

if true, it will return the html string without rendering the whole page. Usefull for debuging, and used for Print Answers

Response

mixed|string

This method is called from Template Editor.

renderTemplateForTemplateEditor(string $sView,array $aData,\Template $oEditedTemplate): string

It returns the HTML string needed for the tmp file using the template twig file.

todo

missing return statement (php warning)

Throws
\Throwable
\Twig_Error_Loader
\Twig_Error_Syntax

Arguments

$sView

string

the view (layout) to render

$aData

array

the datas needed for the view rendering

$oEditedTemplate

\Template

the template to use

Response

string

the generated html

Main method to render a survey.

renderTemplateFromFile(string $sLayout,array $aData,boolean $bReturn): mixed|string
Throws
\CException
\Throwable
\Twig_Error_Loader
\Twig_Error_Syntax
\WrongTemplateVersionException

Arguments

$sLayout

string

the name of the layout to render

$aData

array

the datas needed to fill the layout

$bReturn

boolean

if true, it will return the html string without rendering the whole page. Usefull for debuging, and used for Print Answers

Response

mixed|string

Main method to render an admin page or block.

renderViewFromFile( $sLayoutFilePath,array $aData,boolean $bReturn = false,boolean $bUseRootDir = true): string

Extendable to use admin templates in the future currently running on pathes, like the yii render methods go.

todo

missing return statement (php warning)

Throws
\CException
\Throwable
\Twig_Error_Loader
\Twig_Error_Syntax

Arguments

$sLayoutFilePath

$aData

array

the datas needed to fill the layout

$bReturn

boolean

if true, it will return the html string without rendering the whole page. Usefull for debuging, and used for Print Answers

$bUseRootDir

boolean

Prepend application root dir to sLayoutFilePath if true.

Response

string

HTML

Sets Twig lexer options to change templates syntax

setLexerOptions(array $options)
inherited

Arguments

$options

array

@see self::$lexerOptions

Properties

Twig_Extension_Sandbox configuration

sandboxConfig :array
var

Twig_Extension_Sandbox configuration

Type(s)

array

_twig

_twig :
inherited

Type(s)

Custom LS Users Extensions Example: array('HelloWorld_Twig_Extension')

user_extensions :array
var

Custom LS Users Extensions Example: array('HelloWorld_Twig_Extension')

Type(s)

array

Path alias to Twig

twigPathAlias :string
inherited
var

Path alias to Twig

Type(s)

string

Twig template files extension

fileExtension :string
inherited
var

Twig template files extension

Type(s)

string

Twig environment options

options :array
inherited
var

Twig environment options

see

Type(s)

array

Objects or static classes Keys of array are names to call in template, values - objects or names of static class as string Example: array('html'=>'CHtml', 'clientScript'=>Yii::app()->clientScript) Than in template: {{ html.link('Login', 'site/login') }} or {{ clientScript.registerCssFile(...) }}

globals :array
inherited
var

Objects or static classes Keys of array are names to call in template, values - objects or names of static class as string Example: array('html'=>'CHtml', 'clientScript'=>Yii::app()->clientScript) Than in template: {{ html.link('Login', 'site/login') }} or {{ clientScript.registerCssFile(...) }}

Type(s)

array

Custom functions Keys of array are names to call in template, values - names of functions or static methods of some class Example: array('rot13'=>'str_rot13', 'link'=>'CHtml::link') Than in template: {{ rot13('test') }} or {{ link('Login', 'site/login') }}

functions :array
inherited
var

Custom functions Keys of array are names to call in template, values - names of functions or static methods of some class Example: array('rot13'=>'str_rot13', 'link'=>'CHtml::link') Than in template: {{ rot13('test') }} or {{ link('Login', 'site/login') }}

Type(s)

array

Custom filters Keys of array are names to call in template, values - names of functions or static methods of some class Example: array('rot13'=>'str_rot13', 'jsonEncode'=>'CJSON::encode') Then in template: {{ 'test'|rot13 }} or {{ model|jsonEncode }}

filters :array
inherited
var

Custom filters Keys of array are names to call in template, values - names of functions or static methods of some class Example: array('rot13'=>'str_rot13', 'jsonEncode'=>'CJSON::encode') Then in template: {{ 'test'|rot13 }} or {{ model|jsonEncode }}

Type(s)

array

Custom extensions Example: array('Twig_Extension_Sandbox', 'Twig_Extension_Text')

extensions :array
inherited
var

Custom extensions Example: array('Twig_Extension_Sandbox', 'Twig_Extension_Text')

Type(s)

array

Twig lexer options

lexerOptions :array
inherited
var

Twig lexer options

see

Example: Smarty-like syntax array( 'tag_comment' => array('{', '}'), 'tag_block' => array('{', '}'), 'tag_variable' => array('{$', '}') )

Type(s)

array

_paths

_paths :
inherited

Type(s)