The contents of loops (boucles)

The content extracted from the selection made by a SPIP loop is displayed by using tags. Systematically, whenever a table has an SQL field "x", SPIP is able to provide/display the contents of that field by using the syntax #X.


SPIP will not create an SQL query for ALL of the table’s columns (SELECT * ...) in order to retrieve the requested data, but, will, at each occasion, issue a specific data request – in this case, it would be SELECT x, name_of_sql_field FROM spip_table.

Whenever a field does not exist in the SQL table, like “nonexistent_field” in our example above, SPIP will not insert it into the table query, but will attempt to recover a value for the field from a surrounding loop – if there are any. If there is no parent loop with such a field, then SPIP looks into the environment, just as if you had written #ENV{nonexistent_field} instead.


Let’s take an example of an SQL table named "cats" which contains 5 columns: "id_cat", "race", "name", "age", "colour". We can list the contents of that table with:

    <BOUCLE_cats(CATS){par name}>

When automatically analysing the squelette template, SPIP will understand that it should retrieve the name, age and race fields from the SQL table called cats. However, it will not retrieve the fields that it does not need (in this case id_cat and colour), thereby nominally reducing the load on the database server.

Author Mark Baber Published : Updated : 12/03/23

Translations : English, Español, français, Nederlands