SPIP

[ar] [ast] [bg] [br] [ca] [co] [cpf] [cs] [da] [de] [en] [eo] [es] [eu] [fa] [fon] [fr] [gl] [id] [it] [ja] [lb] [nl] [oc] [pl] [pt] [ro] [ru] [sk] [sv] [tr] [uk] [vi] [zh] Espace de traduction

Download
Home > English documentation > Webmasters > Page layout: reference manual of loops and tags > Criteria > criteria IN value1, value2[, value3,..., valueN]

{criteria IN value1, value2[, value3,..., valueN]}

August 2010

All the versions of this article:

{... IN ...} available from SPIP 1.8, 1.8.1 onwards, restricts the selection of results that have a criterion value equal to one of a finite collection of valid values.


{xxxx IN a,b,c,d} available from SPIP 1.8, 1.8.1 onwards, restricts the display of results that have the xxxx criterai equal to a, b, c or d.

The results are sorted in the order indicated (unless explicitly requested to sort them using another sort criteria). It is also possible to select based on character strings, e.g. {titre IN 'China', 'Japan'}

It is similarly possible to pass an array as an argument (from SPIP 1.9 onwards).

This can be an array defined by an #ARRAY tag or perhaps an array originating from a #ENV**{my_post} tag.

If #ENV{my_post} is an array (originating perhaps from form entries where the name attribute ends in []), and if the analysis filters have been deactivated by adding a double asterisk to this tag, then each element of the array will be considered as an argument for IN, SPIP applying the security filters to each of them in turn [1].

The standard formulaire_forum_previsu template file offers an example of using this criteria within a MOTS (keywords) loop, using the criteria {id_mot IN #ENV**{ajouter_mot}}:
this loop only selects the keywords belonging to a collection that is determined dynamically. In this case, the collection will have been constructed by the standard template file called "choix_mots" (select_words), which uses the name=ajouter_mot[] attribute.

Conditional usage of the IN operator within a loop’s criteria

Usage example:

-  If #ID_ARTICLE exists in the environment and has a value:

<BOUCLE_a(ARTICLES) {id_article ?IN 11,12,13}>
will only display articles with an ID that is included in the IN list

<BOUCLE_a(ARTICLES) {id_article ?!IN 11,12,13}>
will only display articles with an ID that is NOT included in the IN list [2]

-  If #ID_ARTICLE does not exist in the environment:

<BOUCLE_a(ARTICLES) {id_article ?IN 11,12,13}>
will display ALL articles including those with an ID in the IN list

<BOUCLE_a(ARTICLES) {id_article ?!IN 11,12,13}>
will also display ALL articles including those with an ID in the IN list [2]

Footnotes

[2Reminder : {id_article !IN 11,12,13} selects the articles with the ID not in the list of 11, 12, 13 (see criterion !operator value)


Show the template of this page Site powered by SPIP | Translation area | Private area