{xxxx IN a,b,c,d}
restricts the display to results with the criterion xxxx 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'}
Pass as argument an array
This is possible and it is also the only way to dynamically pass a list of values with the IN criterion.
Thus:
#SET{my_sections, '1,2,3'}
<BOUCLE_a(ARTICLES){id_rubrique IN #GET{my_sections}}>
<h3>#TITRE</h3>
</BOUCLE_a>
...will not work. Whereas...
#SET{my_sections, #LISTE{1,2,3}}
<BOUCLE_a(ARTICLES){id_rubrique IN #GET{my_sections}}>
<h3>#TITRE</h3>
</BOUCLE_a>
… will work.
This can be an array defined by
or an array from a tag #GET
or#ENV**{my_post}
.
If #ENV{my_post}
is an array (coming for example from form entries whose name attribute ends with []
), 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 template provided in plugins-dist/forum/formulaires/inc-forum_previsu.html provides an example of use with a WORD loop having the {id_mot IN #ENV**{ajouter_mot}}
criterion:
this loop selects only those keywords which belong to a dynamically specified set. Here, this set will have been constructed by the standard template form "choix_mots", which uses the attribute name=ajouter_mot[]
.
Negating the IN operator in loop criteria
<BOUCLE_a(ARTICLES) {id_article !IN 11,12,13}>
… will only display items whose id is not in the IN list (see criterion !operator value).
Conditional usage of the IN operator within a loop’s criteria
Example
- If #ID_ARTICLE exists in the environment:
<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
If on the other hand, #ID_ARTICLE is not present in the environment, these conditional criteria are not operational, and therefore these 2 loops will display all the items whatever their id.
See also
Conditional criteria
Logical operators
Operators