7. Theme tags

To make using themes easier a set of template tags are used for including and referencing other templates.

7.1. themeinclude

This template tag is based on the standard {% include %} by being aware of themes for a user. They use the normal theme resolution methods, but instead of using the standard template loaders they use the theme prefix.

It should be used in any place that a standard include tag is but should always reference a template, not a variable:

{% themeinclude "media/media_inc_preview.html" %}

It will try and load as per the standard theme template resolution.

7.2. themeextends

Like the standard {% extends %} tag, the {% themeextends %} tag builds on it by being theme aware in that it will try and load the correct theme for the user accessing that template. It works in the same way as the standard extends tag, and resolution:

{% themeextends "base/my_base.html" %}

This will extend the current template with the correct theme’d template.

7.3. extends

Only one use case is recommended for using the standard extends tag and that is to load the current themes’ (that is the one that the user requesting the page should see)’ from the database.

A theme has the attribute ‘template_string’ which can return a template from the database:

{% extends theme %}

The variable to use when extending is set in portal.conf as THEME_CONTEXT_NAME. In this example it is set to “theme”. Calling “theme” here will place extend the current template by using the template stored in template_string in the database against the theme that has been set for the user requesting the page, or failing that the default site-wide theme..

7.4. Not using the theme tags

If you plan on using the standard include and extends tag you will find that the templates are trying to load from the base portal_themes directory. The template_loader that they use is not aware of theming, or aware of the user that is trying to access the template.

You can use this to good effect with variable lookups, as they don’t access the filesystem directly, or if you want to bypass the complete theming of Portal.