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

addExtensions(array $extensions)

It's different from the original Yii Twig Extension to take in account our custom sand box

Arguments

$extensions

array

@see self::$extensions

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

Convert a string containing twig tags to an HTML string.

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

Arguments

$sString

string

The string of HTML/Twig to convert

$aDatas

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 $aDatas): array

Arguments

$aDatas

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( $aDatas,\TemplateConfiguration $oTemplate): 

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

Arguments

$aDatas

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)

$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 $aDatas): array

Arguments

$sString

string

$aDatas

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

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

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 $aDatas,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

$aDatas

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 $aDatas,\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

$aDatas

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 $aDatas,boolean $bReturn): mixed|string
Throws
\CException
\Throwable
\Twig_Error_Loader
\Twig_Error_Syntax
\WrongTemplateVersionException

Arguments

$sLayout

string

the name of the layout to render

$aDatas

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 $aDatas,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

$aDatas

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

Properties

Twig_Extension_Sandbox configuration

sandboxConfig :array
var

Twig_Extension_Sandbox configuration

Type(s)

array

_twig

_twig :\Twig_Environment|null
var

Type(s)

\Twig_Environment|null