The syntax of loops

A loop declares both a database table from which to extract information as well the criteria for selection.

 ... for each object ...

Every loop has a name (which must be unique within the template file), this name is used together with the word “BOUCLE” (English: "loop") to mark the start and the end of the loop. In this example, the loop’s name is “_loopname”.

The table is specified either by an alias (written in capital letters) or by the real name of the table (matching the case), for example “spip_articles”. The example uses the “TABLE” alias.

The next components of a loop are the criteria, each of which are always written enclosed in braces. For example, the criterion {par nom} will sort the results according to the “nom” column of the database table.


This loop lists all of the images stored in the database. It draws its data from the database using the DOCUMENTS alias, and the criterion {extension IN jpg,png,gif} selects only those files which have a filename extension matching one in the given list.

<BOUCLE_documents(DOCUMENTS){extension IN jpg,png,gif}>

The #FICHIER tag contains the URL of the image document. A filter named “image_reduire” is applied to the tag. This will resize the image to be at most 300 pixels (in height AND width) and returns an HTML <img> tag for the new scaled image.

Author Thomas Sutton Published : Updated : 04/06/10

Translations : English, Español, français