Variants of templates

by language, by section or by branch

SPIP allows you to manage template variants by section, by branch or by language.

  • Deleted since : SPIP 4.0

Warning about SPIP’s version

This is the "templates by section" ("squelettes par rubriques") plug-in which allows the layout to be customised according to the language or topic of the main object concerned. This plug-in was integrated into the standard distribution of SPIP up to version 3.2.
From SPIP 4.0.0 onwards, you need to install and activate le plugin "squelettes par rubriques" plug-in to use it.

Different layouts

As mentioned in The general principle and the documentation on multilingualism, SPIP allows you to provide variants of the template files for different languages, different sections or any combination of the two.

We may wish, for example, to format all articles in a particular section with a different layout: with a different background colour and text size, or perhaps certain information relating to the keywords highlighted in the text, etc.

Or maybe the articles and/or sub-sections on a given topic ought to be presented differently because they relate to a different type of information: by listing, for example, all member articles in order of their publishing number with a generally brief text description, rather than another section listing articles by date and providing pagination of excerpts of those articles with embedded links to the articles themselves.

Or it might also mean that the site interface is different depending on the language of the article or section.

Variants of templates are a simple, but perhaps at first glance, not necessarily very flexible, way that SPIP offers to provide such functionality.

In order to tell SPIP to use such varying layouts, you only need to create those varying templates and assign them file names that will indicate to SPIP specifically when to apply them:
-  article.en.html : template for articles in the English language,
-  rubrique.html and article.html : default templates, applying to all sections and articles that do not have a particular template, they must be in the same directory as the variants for them to be taken into account.

-  rubrique=22.html: a special template just for the section number 22 itself,
-  article-2.html: a template for all articles contained in section 2 and its sub-sections,
-  article=22.html : template for all articles only in section 22,
-  article-22.html : template for all the articles in section 22 as well as all those in all its sub-sections,

Exhaustive sorted list of template variants

Take as an example the article templates with given values of language and section (although the explanation below remains equally valid for the templates of sections or news items, and of course, whatever the language and numbers of sections).

First of all, remember that SPIP starts its search in the directory where it retrieves the templates to see if there is a file called article.html. Do not create template variants (e.g. a file named article.cs.html) without also creating a article.html file in that same directory, otherwise you risk having the variant being completely ignored in favour of a generic template from a directory with a lower priority.

If such a variant file exists, SPIP opts to use the template files by choosing the one with a file name that is "the most specific", with the section taking precedence over the language code. Listed below (in decreasing order of priority) are examples of the naming possibilities for the template variant file names:

-  article=8.cs.html: If this file exists, it is applicable only to articles in the Czech language for section number 8 (but not the articles contained in its sub-sections).

-  article=8.html: If this file exists, it applies to the articles in section 8 (except for items covered by a file that also specifies the language, as illustrated above).

-  article-2.es.html: If this file exists, it applies to articles in Spanish contained in section 2 AND its sub-sections. If section 8 is a sub-section of section 2, and both files above exist, then they would take priority.

-  article-2.html: If this file exists, it applies to articles contained in section 2 and its sub-sections (except for articles covered by the files listed above).

-  article.vi.html: If this file exists, it applies to articles in Vietnamese, in all sections (except for articles covered by the files listed above).

-  Finally, the file article.html applies to all articles which have not been covered by the files listed above. And, we repeat, it is absolutely necessary that this file also does exist in that same template directory.

Author Mark, Teddy Published : Updated : 10/07/23

Translations : عربي, català, English, Español, français, italiano, Nederlands