Skip to content

Commit caa16d3

Browse files
authored
Merge pull request simplesamlphp#1174 from ghalse/enhancement/twig-theme-parent
Allow themes to inherit module templates
2 parents 7c6817d + 2840d23 commit caa16d3

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

docs/simplesamlphp-theming.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ If you need to make more extensive customizations to the base template, you shou
131131

132132
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/...`
133133

134+
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.
135+
134136
Even more advanced changes can be made by defining a theme controller in `config.php`:
135137

136138
'theme.controller' => '\SimpleSAML\Module\mymodule\FancyThemeController',

lib/SimpleSAML/XHTML/Template.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ private function setupTwigTemplatepaths()
244244
$templateDirs[] = [
245245
$this->theme['module'] => TemplateLoader::getModuleTemplateDir($this->theme['module'])
246246
];
247+
$templateDirs[] = ['__parent__' => TemplateLoader::getModuleTemplateDir($this->module)];
247248
} catch (\InvalidArgumentException $e) {
248249
// either the module is not enabled or it has no "templates" directory, ignore
249250
}
@@ -524,7 +525,7 @@ public function send()
524525
public function show()
525526
{
526527
if ($this->useNewUI) {
527-
echo $this->getContents();
528+
echo $this->getContents();
528529
} else {
529530
require($this->findTemplatePath($this->template));
530531
}

0 commit comments

Comments
 (0)