{% extends "base.twig" %} {% block content %}

Sandbox

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.

Localization

{% set variable = 'Hello, Untranslated World!' %}

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.

Usage examples

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:

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.

{% set variable = 'Hello, %who%!' %} {% set world = 'World'|trans %} {% set who = {'%who%': world} %}

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.

{% endblock content %}