Coding with SPIP 3.0
SPIP3.0 Technical Documentation

> > > > The syntax of loops

The syntax of loops

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

  1. <BOUCLE_loopname(TABLE){criterion1}{criterion2}>
  2. ... for each object ...
  3. </BOUCLE_loopname>

Download

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.

Example

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.

  1. <BOUCLE_documents(DOCUMENTS){extension IN jpg,png,gif}>
  2. [(#FICHIER|image_reduire{300})]
  3. </BOUCLE_documents>

Download

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.