{% extends "base.twig" %} {% block content %}
This page serves as a demonstration of the new template and translation sub-systems in
SimpleSAMLphp. The page itself is written as a Twig template, which is very similar to other
templating languages, stored in the templates
directory.
Twig templates allow you to print values of variables very easily. For example, the code {{ '{{ ' }}
sometext }}
will print the following text, contained in the variable sometext
:
{{ sometext }}
Twig supports setting your own variables, control structures like if
clauses and loops.
Take a look at the Twig documentation for
template designers if you want to know more.
This page is written in english only, but the examples used here are translated to several languages. The current language is {{ currentLanguage }}. Change to other languages to see the examples change.
Twig allows you to translate strings in your templates. There are several ways to do that. If you want to translate the following text: Hello, Untranslated World!, you can do it with:
{{ '{%' }} trans 'Hello, Untranslated World! %}
you would get
"{% trans 'Hello, Untranslated World!' %}".{{ '{%' }} trans %}Hello, Untranslated World!{{ '{%' }} endtrans
%}
you would get "{% trans %}Hello, Untranslated World!{% endtrans %}".{{ '{{' }} variable|trans }}
you would get "{{ variable|trans }}".Translations support arguments too, so that you can replace parts of the translated string with the contents of
variables. Just use placeholders of the form %variable%
in the place where the contents of the
variables should be placed, and pass an associative array to the trans
filter.
If you have a variable with the text "Hello, %who%!
" The code {{ '{{' }}
variable|trans({'%who%': 'World' }) }}
will print "{{ variable|trans({'%who%': 'World' }) }}". The array
can also be passed in a variable, so that {{ '{{' }} variable|trans(who) }}
will output
"{{ variable|trans(who) }}" when the variable who
is defined as {'%who%': world}
and
world
is also a variable with the translation of the contents, for example, {{ '{%' }}
set world = 'World'|trans %}
. Note that placeholders have names, so order is irrelevant, and can be
changed between translations.