Skip to content

Commit

Permalink
Dev: optimized twig rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Jan 23, 2018
1 parent 52ad855 commit 5838137
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 19 deletions.
4 changes: 2 additions & 2 deletions application/controllers/PrintanswersController.php
Expand Up @@ -130,7 +130,7 @@ function actionView($surveyid, $printableexport = false)
$aData['aSurveyInfo']['printAnswersHeadFormQueXMLUrl'] = Yii::App()->getController()->createUrl('printanswers/view/', array('surveyid'=>$iSurveyID, 'printableexport'=>'quexmlpdf'));

if (empty($sExportType)) {
$aData['aSurveyInfo']['include_content'] = 'printanswers.twig';
$aData['aSurveyInfo']['include_content'] = 'printanswers';
Yii::app()->twigRenderer->renderTemplateFromFile('layout_global.twig', $aData, false);
} else if ($sExportType == 'pdf') {
// Get images for TCPDF from template directory
Expand All @@ -149,7 +149,7 @@ function actionView($surveyid, $printableexport = false)
// Since all data are loaded, and don't need JavaScript, pretend all from Group 1
LimeExpressionManager::StartProcessingGroup(1, ($aSurveyInfo['anonymized'] != "N"), $iSurveyID);
$aData['aSurveyInfo']['printPdf'] = 1;
$aData['aSurveyInfo']['include_content'] = 'printanswers.twig';
$aData['aSurveyInfo']['include_content'] = 'printanswers';
$html = Yii::app()->twigRenderer->renderTemplateFromFile('layout_global.twig', $aData, true);
Yii::app()->clientScript->registerPackage($oTemplate->sPackageName);
$oPDF->writeHTML($html, true, false, true, false, '');
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/RegisterController.php
Expand Up @@ -512,7 +512,7 @@ private function display($iSurveyId, $iTokenId = null, $registerContent)
$aData['aSurveyInfo']['registration_view'] = $registerContent;

$aData['aSurveyInfo']['registerform']['hiddeninputs'] = '<input value="'.$aData['aSurveyInfo']['sLanguage'].'" type="hidden" name="lang" id="register_lang" /><input value="true" type="hidden" name="register"id="register_register" />';
$aData['aSurveyInfo']['include_content'] = 'register.twig';
$aData['aSurveyInfo']['include_content'] = 'register';
Yii::app()->twigRenderer->renderTemplateFromFile('layout_global.twig', $aData, false);

}
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/survey/index.php
Expand Up @@ -425,7 +425,7 @@ public function action()
$aLoadForm['aErrors'] = empty($aLoadErrorMsg) ? null : $aLoadErrorMsg; // Set tit to null if empty
$thissurvey['aLoadForm'] = $aLoadForm;
//$oTemplate->registerAssets();
$thissurvey['include_content'] = 'load.twig';
$thissurvey['include_content'] = 'load';
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=>Survey::model()->findByPk($surveyid), 'aSurveyInfo'=>$thissurvey), false);
}

Expand Down
12 changes: 6 additions & 6 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -464,7 +464,7 @@ public function run($surveyid, $args)
$this->aSurveyInfo['aLEM']['debugvalidation']['message'] = $this->aMoveResult['message'];
}

$this->aSurveyInfo['include_content'] = 'main.twig';
$this->aSurveyInfo['include_content'] = 'main';
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=> Survey::model()->findByPk($this->iSurveyid), 'aSurveyInfo'=>$this->aSurveyInfo), false);
}

Expand Down Expand Up @@ -968,7 +968,7 @@ private function saveAllIfNeeded()
// $cSave->showsaveform($this->aSurveyInfo['sid']); // generates a form and exits, awaiting input
$this->aSurveyInfo['aSaveForm'] = $cSave->getSaveFormDatas($this->aSurveyInfo['sid']);

$this->aSurveyInfo['include_content'] = 'save.twig';
$this->aSurveyInfo['include_content'] = 'save';
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=> Survey::model()->findByPk($this->iSurveyid), 'aSurveyInfo'=>$this->aSurveyInfo), false);
} else {
// Intentional retest of all conditions to be true, to make sure we do have tokens and surveyid
Expand Down Expand Up @@ -1008,7 +1008,7 @@ private function saveSubmitIfNeeded()
// reshow the form if there is an error
if (!empty($aResult['aSaveErrors'])) {
$this->aSurveyInfo['aSaveForm'] = $cSave->getSaveFormDatas($this->aSurveyInfo['sid']);
$this->aSurveyInfo['include_content'] = 'save.twig';
$this->aSurveyInfo['include_content'] = 'save';
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=> Survey::model()->findByPk($this->iSurveyid), 'aSurveyInfo'=>$this->aSurveyInfo), false);
}

Expand Down Expand Up @@ -1067,7 +1067,7 @@ private function moveSubmitIfNeeded()
$completed = templatereplace($this->aSurveyInfo['surveyls_endtext'], array(), $redata, 'SubmitEndtextI', false, null, array(), true);
$this->completed = $completed;

$this->aSurveyInfo['include_content'] = 'submit_preview.twig';
$this->aSurveyInfo['include_content'] = 'submit_preview';
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=> Survey::model()->findByPk($this->iSurveyid), 'aSurveyInfo'=>$this->aSurveyInfo), false);
} else {

Expand Down Expand Up @@ -1167,7 +1167,7 @@ private function moveSubmitIfNeeded()
if ($this->aSurveyInfo['printanswers'] != 'Y') {
killSurveySession($this->iSurveyid);
}
$this->aSurveyInfo['include_content'] = 'submit.twig';
$this->aSurveyInfo['include_content'] = 'submit';
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=> Survey::model()->findByPk($this->iSurveyid), 'aSurveyInfo'=>$this->aSurveyInfo), false);
}
}
Expand Down Expand Up @@ -1493,7 +1493,7 @@ private function manageClearAll()
$restarturl = Yii::app()->getController()->createUrl("survey/index/sid/$this->iSurveyid", $restartparam);

$this->aSurveyInfo['surveyUrl'] = $restarturl;
$this->aSurveyInfo['include_content'] = 'clearall.twig';
$this->aSurveyInfo['include_content'] = 'clearall';
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=> Survey::model()->findByPk($this->iSurveyid), 'aSurveyInfo'=>$this->aSurveyInfo), false);
}
}
Expand Down
6 changes: 3 additions & 3 deletions application/helpers/frontend_helper.php
Expand Up @@ -1261,7 +1261,7 @@ function renderRenderWayForm($renderWay, array $scenarios, $sTemplateViewPath, $
// Rendering layout_user_forms.twig
$thissurvey["aForm"] = $aForm;
$thissurvey['surveyUrl'] = App()->createUrl("/survey/index", array("sid"=>$surveyid));
$thissurvey['include_content'] = 'userforms.twig';
$thissurvey['include_content'] = 'userforms';

Yii::app()->twigRenderer->renderTemplateFromFile("layout_user_forms.twig", array('oSurvey'=>Survey::model()->findByPk($surveyid), 'aSurveyInfo'=>$thissurvey), false);
break;
Expand Down Expand Up @@ -1867,7 +1867,7 @@ function checkCompletedQuota($surveyid, $return = false)
header("Location: ".$sUrl);
}
}
$thissurvey['include_content'] = 'quotas.twig';
$thissurvey['include_content'] = 'quotas';
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=>Survey::model()->findByPk($surveyid), 'aSurveyInfo'=>$thissurvey), false);
}

Expand Down Expand Up @@ -1962,7 +1962,7 @@ function display_first_page($thissurvey, $aSurveyInfo)
$thissurvey['surveyUrl'] = Yii::app()->getController()->createUrl("survey/index", array("sid"=>$surveyid)); // For form action (will remove newtest)
$thissurvey['attr']['welcomecontainer'] = $thissurvey['attr']['surveyname'] = $thissurvey['attr']['description'] = $thissurvey['attr']['welcome'] = $thissurvey['attr']['questioncount'] = '';

$thissurvey['include_content'] = 'firstpage.twig';
$thissurvey['include_content'] = 'firstpage';

Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=>Survey::model()->findByPk($surveyid), 'aSurveyInfo'=>$thissurvey), false);
}
Expand Down
2 changes: 1 addition & 1 deletion themes/survey/vanilla/views/README.md
Expand Up @@ -16,7 +16,7 @@ In vanilla, layout_user_forms and layout_global are pretty similar, and share so
## Content system
layout_global.twig renders the specific content via this statement:
```
{% set sViewContent = './subviews/content/' ~ aSurveyInfo.include_content %}
{% set sViewContent = './subviews/content/' ~ aSurveyInfo.include_content ~ '.twig' %}
{% include './subviews/content/outerframe.twig' with {'include_content': sViewContent } %}
```

Expand Down
17 changes: 13 additions & 4 deletions themes/survey/vanilla/views/layout_global.twig
Expand Up @@ -69,21 +69,25 @@

<!DOCTYPE html>
<html lang="{{ aSurveyInfo.languagecode }}" dir="{{ aSurveyInfo.dir }}" class="{{ aSurveyInfo.languagecode }} dir-{{ aSurveyInfo.dir }} {{ aSurveyInfo.class.html }}" {{ aSurveyInfo.attr.html }}>

{% block head %}
{# Headers, metadata, etc #}
{{ include('./subviews/header/head.twig') }}

{% endblock %}
<body class=" {{ aSurveyInfo.class.body }} font-{{ aSurveyInfo.options.font }} lang-{{aSurveyInfo.languagecode}} {{aSurveyInfo.surveyformat}} {% if( aSurveyInfo.options.brandlogo == "on") %}brand-logo{%endif%}" {{ aSurveyInfo.attr.body }} >
{% if (aSurveyInfo.options.ajaxmode == "on" and aSurveyInfo.printPdf != 1) %}
{% block ajaxindicator %}
{# In vanilla, this file is empty, we keep it to have a common layout between all core themes #}
{{ include('./subviews/navigation/ajax_indicator.twig') }}
{% endblock %}

{% endif %}

{# This used for the pjax system #}
{% block pjaxbegin %}
<div id="beginScripts" class="script-container">
<###begin###>
</div>

{% endblock %}
{# Ajaxify cannot handle an element that is a direct child of body, so => create simple wrapper section #}
<article>

Expand All @@ -106,7 +110,7 @@
Content depends on the action (survey, questions, register, assesments, submit, etc)
Action are in ./subviews/content/
#}
{% set sViewContent = './subviews/content/' ~ aSurveyInfo.include_content %}
{% set sViewContent = './subviews/content/' ~ aSurveyInfo.include_content ~ '.twig' %}
{% include './subviews/content/outerframe.twig' with {'include_content': sViewContent } %}
{% endblock %}

Expand All @@ -123,12 +127,17 @@

{% endblock %}
</div>

</article>
{% block pjaxend %}
<div id="bottomScripts" class="script-container">
<###end###>
</div>
{% endblock %}
{% block themescripts %}
<script>
window.basicThemeScripts.init();
</script>
{% endblock %}
</body>
</html>
2 changes: 1 addition & 1 deletion themes/survey/vanilla/views/subviews/content/README.md
Expand Up @@ -6,7 +6,7 @@

layout_global.twig renders the specific content via this statement:
```
{% set sViewContent = './subviews/content/' ~ aSurveyInfo.include_content %}
{% set sViewContent = './subviews/content/' ~ aSurveyInfo.include_content ~ '.twig'%}
{% include './subviews/content/outerframe.twig' with {'include_content': sViewContent } %}
```

Expand Down

0 comments on commit 5838137

Please sign in to comment.