Skip to content

Commit 2f9ba26

Browse files
committed
Update theme docs for 2.0
1 parent d694d4d commit 2f9ba26

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

docs/simplesamlphp-theming.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ Theming the user interface in SimpleSAMLphp
1010

1111
<!-- {{TOC}} -->
1212

13-
In SimpleSAMLphp every part that needs to interact with the user by using a web page, uses templates to present the XHTML. SimpleSAMLphp comes with a default set of templates that presents a anonymous look.
13+
In SimpleSAMLphp every part that needs to interact with the user by using a web page, uses templates to present the HTML. SimpleSAMLphp comes with a default set of templates that presents a anonymous look.
1414

1515
You may create your own theme, where you add one or more template files that will override the default ones. This document explains how to achieve that.
1616

1717

1818
How themes work
19-
--------------------
19+
----------------
2020

21-
If you want to customize the UI, the right way to do that is to create a new **theme**. A theme is a set of templates that can be configured to override the default templates.
21+
If you want to customize the UI, the right way to do that is to create a new **theme**. A theme is a set of templates that can be configured to override the default templates. Themes are a special type of SimpleSAMLphp module.
2222

2323
### Configuring which theme to use
2424

@@ -33,12 +33,10 @@ In `config.php` there is a configuration option that controls theming. You need
3333

3434
The `theme.use` parameter points to which theme that will be used. If some functionality in SimpleSAMLphp needs to present UI in example with the `logout.twig` template, it will first look for `logout.twig` in the `theme.use` theme, and if not found it will all fallback to look for the base templates.
3535

36-
All required templates SHOULD be available as a base in the `templates` folder, and you SHOULD never change the base templates. To customize UI, add a new theme within a module that overrides the base templates, instead of modifying it.
37-
3836
### Override only specific templates
3937

4038
The SimpleSAMLphp templates are derived from a base template and include other templates as building blocks. You only need to override the templates or building blocks needed for your change.
41-
SimpleSAMLphp allows themes to override the included templates files only, if needed. That means you can create a new theme `fancytheme` that includes only a header and footer template. These templates may refer to your own CSS files, which means that a simple way of making a new look on SimpleSAMLphp is to create a new theme, and copy the existing header, but point to your own CSS instead of the default CSS.
39+
SimpleSAMLphp allows themes to override the included templates files only, if needed. That means you can create a new theme `fancytheme` that includes only a header and footer template. These templates may refer to your own CSS files, which means that a simple way of making a new look on SimpleSAMLphp is to create a new theme, and copy the existing header, but point to your own CSS instead of the default CSS. This means that for many theme requirements, you only need to specify a new header and footer template, and leave all other templates to SimpleSAMLphp's base versions.
4240

4341

4442
Creating your first theme
@@ -64,7 +62,7 @@ Next, we copy the header file from the base theme:
6462

6563
cp templates/_header.twig modules/mymodule/themes/fancytheme/default/
6664

67-
In the `modules/mymodule/themes/fancytheme/default/includes/_header.twig` file type in something and go to the SimpleSAMLphp front page to see that your new theme is in use.
65+
In the `modules/mymodule/themes/fancytheme/default/_header.twig` file, type in something and go to the SimpleSAMLphp front page to see that your new theme is in use.
6866

6967
Adding resource files
7068
---------------------
@@ -78,7 +76,7 @@ modules
7876
└───themes
7977
└───www
8078
└───assets
81-
└───logo.png
79+
└───logo.svg
8280
└───style.css
8381
```
8482

@@ -90,10 +88,24 @@ Example for a custom CSS stylesheet file:
9088
{% endblock %}
9189
```
9290

91+
A custom theme controller
92+
-------------------------
93+
94+
If you have very specific requirements for your theme, you can define a custom theme controller
95+
in `config.php`:
96+
97+
'theme.controller' => '\SimpleSAML\Module\mymodule\FancyThemeController',
98+
99+
This requires you to implement `\SimpleSAML\XHTML\TemplateControllerInterface.php` in your module's `lib`-directory.
100+
The class can then modify the Twig Environment and the variables passed to the theme's templates. In short, this allows you to set additional global variables and to write your own Twig filters and functions.
101+
102+
See the [Twig documentation](https://twig.symfony.com/doc/2.x/templates.html) for more information on using variables and expressions in Twig templates, and the SimpleSAMLphp wiki for [our conventions](https://github.com/simplesamlphp/simplesamlphp/wiki/Twig-conventions).
103+
93104
Migrating to Twig templates
94105
---------------------------
95106

96-
In version 1.15, a new templating system based on [Twig](https://twig.symfony.com/) was introduced. As modules migrate, it will become necessary for themes to include both the old templating style described above and new Twig-based templates.
107+
For existing themes that have been created before SimpleSAMLphp 2.0, you may need to upgrade them to the Twig
108+
templating enging to be compatible with SimpleSAMLphp 2.0.
97109

98110
Twig works by extending a base template, which can itself include other partial templates. Some of the content of the old `includes/header.php` template is now located in a separate `_header.twig` file. This can be customized by copying it from the base template:
99111

@@ -104,16 +116,8 @@ If you need to make more extensive customizations to the base template, you shou
104116
cp templates/base.twig modules/mymodule/themes/fancytheme/default/
105117

106118
Any references to `$this->data['baseurlpath']` in old-style templates can be replaced with `{{baseurlpath}}` in Twig templates. Likewise, references to `\SimpleSAML\Module::getModuleURL()` can be replaced with `{{baseurlpath}}module.php/mymodule/...` or the `asset()` function like shown above.
119+
If you want to use the `asset()` function, you need to move the asserts from `www/` to `www/assets/`.
107120

108121
Within templates each module is defined as a separate namespace matching the module name. This allows one template to reference templates from other modules using Twig's `@namespace_name/template_path` notation. For instance, a template in `mymodule` can include the widget template from the `yourmodule` module using the notation `@yourmodule/widget.twig`. A special namespace, `__parent__`, exists to allow theme developers to more easily extend a module's stock template.
109122

110-
Even more advanced changes can be made by defining a theme controller in `config.php`:
111-
112-
'theme.controller' => '\SimpleSAML\Module\mymodule\FancyThemeController',
113-
114-
This requires you to implement `\SimpleSAML\XHTML\TemplateControllerInterface.php` in your module's `lib`-directory.
115-
The class can then modify the Twig Environment and the variables passed to the theme's templates. In short, this allows you to set additional global variables and to write your own Twig filters and functions.
116-
117-
See the [Twig documentation](https://twig.symfony.com/doc/1.x/templates.html) for more information on using variables and expressions in Twig templates, and the SimpleSAMLphp wiki for [our conventions](https://github.com/simplesamlphp/simplesamlphp/wiki/Twig-conventions).
118-
119123
The wiki also includes some information on [migrating translations](https://github.com/simplesamlphp/simplesamlphp/wiki/Migrating-translation-in-Twig) and [migrating templates](https://github.com/simplesamlphp/simplesamlphp/wiki/Twig:-Migrating-templates).

0 commit comments

Comments
 (0)