The subtleties of templates

Filtres turn the content of the database into well presented HTML code

If the LOOPS make it possible to structure the page in a logical manner, all that remains is to present the content in an aesthetic way. SPIP cannot design the page for you but you can make use of its filters...

Content stored in the database is presented in the form of a block of text, and you will want to manipulate it before displaying it on the screen. Filters are made for this:

-  the most used filters (they are applied automatically) are |typo and |propre; the first is a typographical corrector, whose principal mission is to add non-breaking spaces where they are needed (refer to SPIP’s online help); the second looks after formatting paragraphs and applying styles to text marked with SPIP shortcuts (italics, bold, subtitles, etc.) - by default it is only applied to long texts (#TEXTE, #CHAPO, etc.)

-  other filters are very useful: for example |majuscules (display in capital letters), |justifier (justify text) or |aligner_droite (right align the text), or the esoteric |saison (season - which displays "summer" if the variable is a date ranging between 21 June and 20 September).

To use a filter it is necessary to enclose the variable in round and in square brackets (we will see the implications later): [blah blah (#VARIABLE|filter) blah blah]

It is possible to concatenate filters [1] like this: [(#DATE_REDAC|saison|majuscules)] would display "WINTER"

Exercise covering all the lessons up to this one: Try to display, in capitals, the titles of the 10 most recent articles in the section passed in context, and to put at the top of the page the current season (i.e. the season in which the most recent article in the whole database was published).


Why the brackets? Let us suppose that your database contains dated articles and others not dated. The variable #DATE equals "2003-07-01 10-53-01" (MySQL format) in the first case, and "0000-00-00 00-00-00" in the second case. To display the date in a nice format we will use the following lines in the template:

[<table border="1"><tr><td>

Here the filter |affdate displays the date in letters (in the format "1st July 2003"), but returns a null string if the date is unknown (equal to "0000..."). The square brackets enclose the text to be displayed on either side of the date if the result between brackets is not a null string.

Result: only the dated articles cause the display of a table containing the date. A well-designed template will define precisely what should or should not be displayed according to the content... Filters are also useful for this.


[1What we call "pipeline..."

Note that certain presentation filters can be replaced by style sheets. Thus |majuscules is equivalent to the CSS attribute "text-transform: uppercase" and |justifier is equivalent to "text-align: justify".

See SPIP and Style Sheets (CSS) for more details on CSS styles offered by SPIP. (yet to be translated).

Author Paul Knight Published : Updated : 18/06/15

Translations : عربي, català, corsu, Deutsch, English, Español, français, italiano, Nederlands, Português, русский, slovenčina, Türkçe, українська