|singulier_ou_pluriel{xxx:single_item_string, xxx:several_items_string}

The |singulier_ou_pluriel filter is used to vary an output display depending on the numeric value returned by the tag to which it is applied.

  • New in : SPIP 2.0

The |singulier_ou_pluriel filter is usually applied to assign (singular or plural) character strings depending on the return value of a tag.


Let’s say that we have the following declarations in our local_xx.php language file:

'quantity_something_one'   => 'there was 1 result returned by this loop.',
'quantity_something_more' => 'there were @nb@ results returned in this loop.'

And then we code a SPIP loop as below:

<BOUCLE_a(ARTICLES) {criteria...}>
[(#TOTAL_BOUCLE|singulier_ou_pluriel{local:quantity_something_one, local:quantity_something_more, nb})]

-  If the loop only returns a single entry, then it will display:

there was 1 result returned by this loop. 

-  If the loop returns 36 entries, then it will display:

'there were 36 results returned in this loop.

Note: if the value provided is null, the filter returns nothing, allowing the |sinon filter to be used next.

This filter explicitly expects some language idioms as its arguments. You should therefore not pass it any language tags:
|singulier_ou_pluriel{module:one_item, module:more_items}
is the correct syntax;
|singulier_ou_pluriel{<:module:one_item:>, <:module:more_items:>}
is the incorrect syntax .

Customize filter

As of SPIP 4.0, it is possible to define functions to customise the operation of this filter
-  for a particular language. This is done by defining a function suffixed with the language code. For example, the functionsingulier_ou_pluriel_ar() for the Arabic language.
-  or generically for all languages. Indeed, SPIP uses charger_fonction to get the version of singulier_ou_pluriel specialized by you.

Author Mark Published : Updated : 22/04/23

Translations : català, English, français, Nederlands