styliser

This pipeline modifies the way in which SPIP searches for the template to use to compute a page - and for example, to change it for a specific section.

You can use it like this :

  1. // pipeline styliser
  2. $template = pipeline('styliser', array(
  3. 'args' => array(
  4. 'id_rubrique' => $sectionId,
  5. 'ext' => $ext,
  6. 'fond' => $initialTemplate,
  7. 'lang' => $lang,
  8. 'connect' => $connect
  9. ),
  10. 'data' => $template,
  11. ));

Download

It receives some arguments found in the environment context and returns the name of the template that will be used by the compilation.

If the url is spip.php?article18, the arguments will be :

  • id_rubrique = 4 (if the article is in section number 4)
  • ext = ’html’ (the default extension for templates)
  • fond = ’article’ (name of the template initially used)
  • lang = ’fr’
  • connect = ’’ (SQL connection name).

Example :

The plugin "Spip-Clear" uses this pipeline to call some specific templates for the different branches of the blog:

  1. // defines the template to use for a section of Spip-Clear
  2. function spipclear_styliser($flux){
  3. // article or section ?
  4. if (($fond = $flux['args']['fond'])
  5. AND in_array($fond, array('article','rubrique'))) {
  6.  
  7. $ext = $flux['args']['ext'];
  8. // [...]
  9.  
  10. if ($section_id = $flux['args']['id_rubrique']) {
  11. // calculates the branch
  12. $branch_id = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($section_id));
  13. // comparison of the branch with the config of Spip-Clear
  14. if (in_array($branch_id, lire_config('spipclear/secteurs', 1))) {
  15. // if the template $fond_spipclear exists
  16. if ($template = test_squelette_spipclear($fond, $ext)) {
  17. $flux['data'] = $template;
  18. }
  19. }
  20. }
  21. }
  22. return $flux;
  23. }
  24.  
  25. // returns a template $fond_spipclear.$ext when it exists
  26. function test_squelette_spipclear($fond, $ext) {
  27. if ($template = find_in_path($fond."_spipclear.$ext")) {
  28. return substr($template, 0, -strlen(".$ext"));
  29. }
  30. return false;
  31. }

Download

Author Gilles Vincent Published : Updated : 30/05/10

Translations : English, français