Test filters

There are several filters used for tests and logical operations. These are the filters "?", "sinon" (else in French), "oui", "non", "et", "ou", "xou" which are generally used in most cases.

  • |?{vrai,faux} returns "faux" (false in French) if what is input to the filter is empty or null, otherwise it returns "vrai" (true in French) - this might be better interpreted in English as "boolean_does_this_thing_have_a_value".
  • |sinon{this text} returns "this text" only if what is input to the filter is empty, otherwise it simply returns that same input - this might be better interpreted in English as "but_if_empty_put_this_instead".
  • |oui returns either a space or nothing. It is equivalent to |?{' ',''} or |?{' '} and is used to return a non-empty content (a space) to indicate that the optional parts of the tags should be displayed.
  • |non is the opposite of |oui and is equivalent to |?{'',' '}
  • |et is used to confirm the existence of 2 elements (logical AND)
  • |ou is used to confirm the existence of either 1 or 2 elements (logical OR)
  • |xou is used to confirm the existence of one, and only one, of the two elements (logical XOR).

In addition, SPIP will also understand the English equivalents for these: "yes", "not", "or", "and" and "xor".

Example

// display the short description if it exists, otherwise the beginning of the text
[(#CHAPO|sinon{#TEXTE|couper{200}})]
 // displays "This title is long" only if the title is longer than 30 characters
[(#TITRE|strlen|>{30}|yes) This title is long ]
 
[(#CHAPO|no) There is no short description ]
[(#CHAPO|and{#TEXTE}) There is a short description, and a text ]
[(#CHAPO|and{#TEXTE}|non) The two do not exist at the same time ]
[(#CHAPO|or{#TEXTE}) There is either a short description, a text, or both ]
[(#CHAPO|or{#TEXTE}|non) There is neither one nor the other ]
[(#CHAPO|xor{#TEXTE}) There is one, or the other, but not both, and not neither ]
[(#CHAPO|xor{#TEXTE}|non) Neither or both, but not just one of the two ]

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

Translations : English, français, Nederlands