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(\Template $oTemplate) 

Arguments

$oTemplate

\Template

the template where to start

Convert a string containing twig tags to an HTML string.

convertTwigToHtml(string $sString, array $aDatas, \TemplateConfiguration $oTemplate) : string

Arguments

$sString

string

The string of HTML/Twig to convert

$aDatas

array

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

Response

string

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

Plugin event, should be replaced by Question Template

getPluginsData(string $sString,  $aDatas) 

Arguments

$sString

string

$aDatas

Find which template should be used to render a given view

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

Arguments

$sView

string

the view (layout) to render

$oRTemplate

\Template

the template where the custom option page should be looked for

Response

\Template|boolean

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

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

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.

Arguments

$sView

string

the view (layout) to render

$aData

array

the datas needed for the view rendering

Response

string

the generated html

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.

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) 

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

Properties

Twig_Extension_Sandbox configuration

sandboxConfig : array
var

Twig_Extension_Sandbox configuration

Type(s)

array

_twig

_twig : 

Type(s)