[ar] [ast] [bg] [br] [ca] [co] [cpf] [cs] [da] [de] [en] [eo] [es] [eu] [fa] [fon] [fr] [gl] [id] [it] [ja] [lb] [nl] [oc] [pl] [pt] [ro] [ru] [sk] [sv] [tr] [uk] [vi] [zh] Espace de traduction


Variants of templates

by language, by section or by branch

July 2010

All the versions of this article:

SPIP allows you to offer variations of your "squelette" template files for different sections, branches or languages.

As mentioned at the beginning of the reference manual 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.

Different layouts

We may wish, for example, that all articles in a particular section be formatted 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 the 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 in date order 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:

-  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.en.html: a template for all English articles,
-  rubrique.html and article.html: the default templates, which apply to all sections and articles that do not have a specific template, but whose presence is absolutely necessary in the same directory as the variants of the templates for them to be taken into account.

The complete sorted list of the variants of a template

Take as an example the article templates for 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 first searches 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 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 the 2 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.

Background: Up until SPIP 1.7, SPIP 1.7.2 , if the article.html file didn’t exist, then SPIP would use the article-dist.html file instead which was provided by the default set of templates. For further information, please read the article about What are the files in that “dist” directory?.

Show the template of this page Site powered by SPIP | Translation area | Private area