From 09c1c97e186c2b50ffede2c4a18113c70daf3e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Pe=CC=81rez=20Crespo?= <jaime.perez@uninett.no> Date: Thu, 9 Feb 2017 16:37:43 +0100 Subject: [PATCH] Populate the query parameters in the twig context. This allows us to build the language switching links even when we have query parameters that would otherwise get lost. --- lib/SimpleSAML/XHTML/Template.php | 3 +++ templates/_header.twig | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index 97c17d466..f8332794f 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -333,6 +333,9 @@ class SimpleSAML_XHTML_Template if ($this->translator->getLanguage()->isLanguageRTL()) { $this->data['isRTL'] = true; } + + // add query parameters, in case we need them in the template + $this->data['queryParams'] = $_GET; } diff --git a/templates/_header.twig b/templates/_header.twig index 704e340f6..461dfd25d 100644 --- a/templates/_header.twig +++ b/templates/_header.twig @@ -5,10 +5,18 @@ {% if not hideLanguageBar %} <div id="languagebar"> {% for lang in languageBar %} - - {%- if not loop.first -%} | {% endif -%}{% if lang.url %}<a href="{{ lang.url }}">{{ lang.name }}</a>{% else %}{{ lang.name }}{% endif %} + {%- if not loop.first -%}|{% endif -%} + {% if lang.url %} + <a href="{{ lang.url -}} + {%- if queryParams %}&{% endif -%} + {%- for name, value in queryParams -%} + {%- if not loop.first %}&{% endif -%} + {%- if value %}{{ name }}={{ value }}{% else %}{{ name }}{% endif -%} + {%- endfor %}">{{ lang.name }}</a> + {% else %} + {{ lang.name }} + {% endif %} {% endfor %} - </div> {% endif %} -- GitLab