Declaring options

When a visitor requests a page (whether or not it is in the cache), SPIP carries out a number of actions, one of which is to load the “options” files. In these files we can, for example, define new constants or modify global variables that control the way SPIP operates.

These options can be created in the file config/mes_options.php or in any plug-in by declaring the name of the file in plugin.xml like this: <options>pluginprefix_options.php</options>.

All options files (those of the site, and then those of all the plugins) are loaded every time a page request is made in the public zone or the private zone, so they should be as simple and as small as possible.

This example, from a contribution called “switcher”, will change the set of templates used by the site (or, strictly speaking, the name of the templates folder) depending on the value of the var_skel parameter in the URL.

  1. <?php
  3. // 'name' => 'template path'
  4. $squelettes = array(
  5. '2008'=>'squelettes/2008',
  6. '2007'=>'squelettes/2007',
  7. );
  9. // If a particular set of templates are requested (and exist), set a cookie, otherwise delete the cookie
  10. if (isset($_GET['var_skel'])) {
  11. if (isset($squelettes[$_GET['var_skel']]))
  12. setcookie('spip_skel', $_COOKIE['spip_skel'] = $_GET['var_skel'], NULL, '/');
  13. else
  14. setcookie('spip_skel', $_COOKIE['spip_skel'] = '', -24*3600, '/');
  15. }
  17. // If a particular template path is permitted, define it as the templates folder
  18. if (isset($_COOKIE['spip_skel']) AND isset($squelettes[$_COOKIE['spip_skel']]))
  19. $GLOBALS['dossier_squelettes'] = $squelettes[$_COOKIE['spip_skel']];
  21. ?>


Author Thomas Sutton Published : Updated : 09/05/10

Translations : English, français