Skip to content
Snippets Groups Projects
Unverified Commit 09f4ee18 authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Twig Strict vars (#1264)

* Use strict variables in Twig, except for our TemplateTest; throw exception on missing variables

* Fix issues due to Twig strict_variables=true

* Fix for #1229

* Fix metadata-template
parent 54a6d7d1
No related branches found
No related tags found
No related merge requests found
...@@ -468,7 +468,7 @@ class Translate ...@@ -468,7 +468,7 @@ class Translate
{ {
$text = BaseTranslator::$current->gettext($original); $text = BaseTranslator::$current->gettext($original);
if (func_num_args() === 1) { if (func_num_args() === 1 || $original === null) {
return $text; return $text;
} }
......
...@@ -306,8 +306,9 @@ class Template extends Response ...@@ -306,8 +306,9 @@ class Template extends Response
// set up translation // set up translation
$options = [ $options = [
'cache' => $cache,
'auto_reload' => $auto_reload, 'auto_reload' => $auto_reload,
'cache' => $cache,
'strict_variables' => true,
'translation_function' => [Translate::class, 'translateSingularGettext'], 'translation_function' => [Translate::class, 'translateSingularGettext'],
'translation_function_plural' => [Translate::class, 'translatePluralGettext'], 'translation_function_plural' => [Translate::class, 'translatePluralGettext'],
]; ];
...@@ -513,7 +514,11 @@ class Template extends Response ...@@ -513,7 +514,11 @@ class Template extends Response
if ($this->controller) { if ($this->controller) {
$this->controller->display($this->data); $this->controller->display($this->data);
} }
return $this->twig->render($this->twig_template, $this->data); try {
return $this->twig->render($this->twig_template, $this->data);
} catch (\Twig\Error\RuntimeError $e) {
throw new \SimpleSAML\Error\Exception(substr($e->getMessage(), 0, -1) . ' in ' . $this->template, 0, $e);
}
} }
......
{% extends "base.twig" %} {% extends "base.twig" %}
{% block contentwrapper %} {% block contentwrapper %}
{% if tabname %}
<div id="portalmenu" class="ui-tabs ui-widget ui-widget-content ui-corner-all"> <div id="portalmenu" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
<ul class="tabset_tabs ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all"> <ul class="tabset_tabs ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
{% if links is defined %}
{% for name, link in links %} {% for name, link in links %}
{% if name == pageid %} {% if name == pageid %}
<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"> <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active">
...@@ -14,12 +17,13 @@ ...@@ -14,12 +17,13 @@
</li> </li>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %}
</ul> </ul>
<div id="portalcontent" class="ui-tabs-panel ui-widget-content ui-corner-bottom"> <div id="portalcontent" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
{% endif %}
{{ block('content') }} {{ block('content') }}
{% if tabname %}
</div> </div>
</div> </div>
{% endif %}
{% endblock %} {% endblock %}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="code-box"> <div class="code-box">
<div class="code-box-title"> <div class="code-box-title">
<h3>{{ 'Metadata'|trans }}</h3> <h3>{{ 'Metadata'|trans }}</h3>
<button data-clipboard-target="#metadata" id="btn{{ loop.index }}" class="pure-button right clipboard-btn copy"> <button data-clipboard-target="#metadata" class="pure-button right clipboard-btn copy">
<span class="fa fa-copy"></span> <span class="fa fa-copy"></span>
</button> </button>
</div> </div>
......
...@@ -102,12 +102,12 @@ ...@@ -102,12 +102,12 @@
</dl> </dl>
<br> <br>
{% if logout %} {% if logout is defined %}
<h2>{% trans %}Logout{% endtrans %}</h2> <h2>{% trans %}Logout{% endtrans %}</h2>
<p> {{ logout }}</p> <p> {{ logout }}</p>
{% endif %} {% endif %}
{% if logouturl %} {% if logouturl is defined %}
<div class="center"> <div class="center">
<a class="pure-button pure-button-red" href="{{ logouturl }}">{{ 'Logout'|trans }}</a> <a class="pure-button pure-button-red" href="{{ logouturl }}">{{ 'Logout'|trans }}</a>
</div> </div>
......
<div class="expandable{% if expanded %} expanded{% endif %}"> <div class="expandable{% if expanded is defined %} expanded{% endif %}">
{% if block('general') is defined %} {% if block('general') is defined %}
<div class="general"> <div class="general">
{{- block("general") }} {{- block("general") }}
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{% block content %} {% block content %}
<h2>{% trans %}Metadata{% endtrans %}</h2> <h2>{% trans %}Metadata{% endtrans %}</h2>
<dl> <dl>
<dd>{{ metadata_intro }}</dd> <dd>{{ '{admin:metadata_intro}'|trans }}</dd>
{% if metaurl is defined %} {% if metaurl is defined %}
<dd>{% trans %}You can get the metadata xml on a dedicated URL:{% endtrans %}</dd> <dd>{% trans %}You can get the metadata xml on a dedicated URL:{% endtrans %}</dd>
...@@ -49,9 +49,9 @@ ...@@ -49,9 +49,9 @@
<li> <li>
<a href="{{ cert.url }}"><i class="fa fa-download"></i>{{ cert.name }} <a href="{{ cert.url }}"><i class="fa fa-download"></i>{{ cert.name }}
{#- #}{% if cert.signing %}-signing{% endif %} {#- #}{% if cert.signing is defined %}-signing{% endif %}
{#- #}{% if cert.encryption %}-encryption{% endif %}.pem {#- #}{% if cert.encryption is defined %}-encryption{% endif %}.pem
{#- #}{% if cert.prefix %} ({% trans %}new{% endtrans %}){% endif %}</a> {{ cert.comment }} {#- #}{% if cert.prefix is defined %} ({% trans %}new{% endtrans %}){% endif %}</a> {{ cert.comment }}
</li> </li>
{% endfor %} {% endfor %}
...@@ -59,4 +59,4 @@ ...@@ -59,4 +59,4 @@
{% endif %} {% endif %}
</dl> </dl>
{% endblock content %} {% endblock content %}
\ No newline at end of file
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
{% for idpentry in idplist %} {% for idpentry in idplist %}
{% if idpentry.entityid == preferredidp %} {% if idpentry.entityid == preferredidp %}
<div class="preferredidp"> <div class="preferredidp">
{% if idpentry.iconurl %} {% if idpentry.iconurl is defined %}
<img class="float-l" src="{{ idpentry.iconurl }}"> <img class="float-l" src="{{ idpentry.iconurl }}">
{% endif %} {% endif %}
<h3><i class="fa fa-star"></i> {{ idpentry.name }}</h3> <h3><i class="fa fa-star"></i> {{ idpentry.name }}</h3>
{% if idpentry.description %} {% if idpentry.description is defined %}
<p>{{ idpentry.description }}</p> <p>{{ idpentry.description }}</p>
{% endif %} {% endif %}
<button type="submit" class="btn" name="idp_{{ idpentry.entityid }}">{{'Select'|trans}}</button> <button type="submit" class="btn" name="idp_{{ idpentry.entityid }}">{{'Select'|trans}}</button>
...@@ -31,11 +31,11 @@ ...@@ -31,11 +31,11 @@
{% for idpentry in idplist %} {% for idpentry in idplist %}
{% if idpentry.entityid != preferredidp %} {% if idpentry.entityid != preferredidp %}
{% if idpentry.iconurl %} {% if idpentry.iconurl is defined %}
<img class="float-l" src="{{ idpentry.iconurl }}"> <img class="float-l" src="{{ idpentry.iconurl }}">
{% endif %} {% endif %}
<h3>{{ idpentry.name }}</h3> <h3>{{ idpentry.name }}</h3>
{% if idpentry.description %} {% if idpentry.description is defined %}
<p>{{ idpentry.description }}</p> <p>{{ idpentry.description }}</p>
{% endif %} {% endif %}
<button type="submit" class="btn" name="idp_{{ idpentry.entityid }}">{{'Select'|trans}}</button> <button type="submit" class="btn" name="idp_{{ idpentry.entityid }}">{{'Select'|trans}}</button>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment