The contents of a (template) exec file

A call from within the private zone of a ?exec=name page automatically loads a template located in prive/exec/name.html.

In most cases, it is recommended to use this method rather than a PHP file. The objective being that SPIP’s private zone itself also be written as a template, and therefore be easier to customise. This then makes it possible to use loops, includes, tags, and authorisations just like any other regular SPIP template.

Example of an empty private page template:

  1. <!--#hierarchie-->
  2. <ul id="chemin">
  3. <li>A list of pages constituting a breadcrumb path</li>
  4. </ul>
  5. <!--/#hierarchie-->
  6.  
  7. <h1>A private page directly coded in a template file</h1>
  8. <p>Some page content</p>
  9.  
  10. <!--#navigation-->
  11. <div class='cadre-info'>
  12. Some information in a navigation column.
  13. </div>
  14. <!--/#navigation-->
  15.  
  16. <!--#extra-->
  17. Some extra content in the extra column.
  18. <!--/#extra-->

Download

The <!--#hierarchie-->, <!--#navigation--> and <!--#extra--> frame tags serve to separate the page’s major sections. SPIP’s private zone will automatically relocate each of these sections into the appropriate HTML tags.

If the template only returns an empty result, then SPIP will automatically generate an authorisation error.

From a technical point of view, these templates are processed by the ecrire/exec/fond.php file. The following pipelines are automatically added: affiche_gauche, affiche_droite et affiche_milieu by passing the exec parameter name as a parameter:

  1. echo pipeline('affiche_milieu', array('args' => array('exec' => $exec), 'data' => ''));

In addition, the private page title is calculated by extracting the contents of the first HTML<h1> (or <hn>) tag that is found.

Example

The "Formidable" plugin uses SPIP templates to construct its pages for the private zone. To display responses in a form, it uses the following template code:

  1. <BOUCLE_formulaire(FORMULAIRES){id_formulaire}>
  2. <BOUCLE_autoriser(CONDITION){si #AUTORISER{voir, formulaires_reponse}}>
  3.  
  4. <!--#hierarchie-->
  5. <ul id="chemin">
  6. <li>
  7. <a href="#URL_ECRIRE{formulaires_tous}" class="racine"><:formidable:formulaires_tous:></a>
  8. </li>
  9. <li>
  10. <span class="bloc">
  11. <em>&gt;</em>
  12. <a class="on" href="[(#URL_ECRIRE{formulaires_voir}
  13. |parametre_url{id_formulaire, #ID_FORMULAIRE})]">#TITRE</a>
  14. </span>
  15. </li>
  16. </ul>
  17. <!--/#hierarchie-->
  18.  
  19. <div class="fiche_objet">
  20. <a href="[(#URL_ECRIRE{formulaires_voir}
  21. |parametre_url{id_formulaire, #ID_FORMULAIRE})]" class="icone36" style="float:left;">
  22. <img width="24" height="24" src="#CHEMIN{images/formulaire-24.png}" />
  23. <span><:retour:></span>
  24. </a>
  25.  
  26. <:formidable:voir_reponses:>
  27. <h1>#TITRE</h1>
  28. <div class="nettoyeur"></div>
  29. </div>
  30.  
  31. <INCLURE{fond=prive/liste/formulaires_reponses}{id_formulaire}
  32. {titre=<:formidable:reponses_liste_publie:>}{ajax} />
  33.  
  34. <!--#navigation-->
  35. <div class="cadre infos cadre-info">
  36. <div class="numero">
  37. <:formidable:voir_numero:>
  38. <p>#ID_FORMULAIRE</p>
  39. </div>
  40. <div class="hover">
  41. <a href="#SELF" class="cellule-h">
  42. [<img src="(#CHEMIN{images/formulaire-reponses-24.png})" style="vertical-align:middle;" alt="" />]
  43. <span style="vertical-align:middle;"><:formidable:reponses_liste:></span>
  44. </a>
  45. </div>
  46. <div>
  47. <a href="[(#URL_ECRIRE{formulaires_analyse}
  48. |parametre_url{id_formulaire, #ID_FORMULAIRE})]" class="cellule-h">
  49. [<img src="(#CHEMIN{images/formulaire-analyse-24.png})" style="vertical-align:middle;" alt="" />]
  50. <span style="vertical-align:middle;"><:formidable:reponses_analyse:></span>
  51. </a>
  52. </div>
  53. </div>
  54. <!--/#navigation-->
  55. </BOUCLE_autoriser>
  56. </BOUCLE_formulaire>

Download

Notes:

  • All of this is included within a loop that checks for the existence of the form: if the form does not exist, the template then returns nothing and provides an error message instead.
  • In the same manner, it is surrounded with an #AUTORISER test to check that the current person has the rights to see the responses. In this case we use the CONDITION loop from the "Bonux" plugin in order to be able to continue to read SPIP loops that lie inside the condition.
  • The <!--#hierarchie--> code section displays a suitable path from amongst the private pages of the plugin.

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

Translations : English, français