Generic tags

Another clever SPIP mechanism is the provisioning of tags that might be termed as generic. In fact, it is possible to use a single tag declaration for a whole group of tags prefixed with an identical name.

As such, a tag named #PREFIX_NAME can use a file called balise/prefix_.php and delcare a function balise_PREFIX__dist() which will then be used if there is no balise_PREFIX_NAME_dist($p) function present.

The generic function, which accepts tag attributes in the $p variable, can use $p->name_field to obtain the name of the requested tag (in this case "PREFIX_NAME"). By analysing this name, it can then execute the appropriate actions.

Example

This example is used by the generic tags #FORM_NAME, which are also dynamic fields (in the file ecrire/balise/formulaire_.php).

  1. function balise_FORM__dist($p) {
  2. preg_match(",^FORM_(.*)?$,", $p->name_field, $regs);
  3. $form = $regs[1];
  4. return calculer_balise_dynamique($p,"FORM_$form",array());
  5. }

Download

Author Mark Baber Published : Updated : 12/05/17

Translations : English, français