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

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

Download

Author Mark Baber Published : Updated : 19/06/10

Translations : English, français