Coding with SPIP 2.1
SPIP 2.1 Technical Documentation

> > > > The contents of loops (boucles)

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.

  1. <BOUCLE_myloop(TABLES)>
  2. #X - #NAME_OF_SQL_FIELD - #NONEXISTENT_FIELD<br />
  3. </BOUCLE_myloop>

Download

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.

Example

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:

  1. <B_cats>
  2. <table>
  3. <tr>
  4. <th>Name</th><th>Age</th><th>Race</th>
  5. </tr>
  6. <BOUCLE_cats(CATS){par name}>
  7. <tr>
  8. <td>#NAME</td><td>#AGE</td><td>#RACE</td>
  9. </tr>
  10. </BOUCLE_cats>
  11. </table>
  12. </B_cats>

Download

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.