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:

<!--#hierarchie-->
<ul id="chemin">
	<li>A list of pages constituting a breadcrumb path</li>
</ul>
<!--/#hierarchie-->
 
<h1>A private page directly coded in a template file</h1>
<p>Some page content</p>

<!--#navigation-->
<div class='cadre-info'>
Some information in a navigation column.
</div>
<!--/#navigation-->

<!--#extra-->
Some extra content in the extra column.
<!--/#extra-->

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:

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:

<BOUCLE_formulaire(FORMULAIRES){id_formulaire}>
<BOUCLE_autoriser(CONDITION){si #AUTORISER{voir, formulaires_reponse}}>
 
<!--#hierarchie-->
<ul id="chemin">
	<li>
		<a href="#URL_ECRIRE{formulaires_tous}" class="racine"><:formidable:formulaires_tous:></a>
	</li>
	<li>
		<span class="bloc">
			<em>&gt;</em>
			<a class="on" href="[(#URL_ECRIRE{formulaires_voir}
				|parametre_url{id_formulaire, #ID_FORMULAIRE})]">#TITRE</a>
		</span>
	</li>
</ul>
<!--/#hierarchie-->
 
<div class="fiche_objet">
	<a href="[(#URL_ECRIRE{formulaires_voir}
		|parametre_url{id_formulaire, #ID_FORMULAIRE})]" class="icone36" style="float:left;">
		<img width="24" height="24" src="#CHEMIN{images/formulaire-24.png}" />
		<span><:retour:></span>
	</a>
	
	<:formidable:voir_reponses:>
	<h1>#TITRE</h1>
	<div class="nettoyeur"></div>
</div>
 
<INCLURE{fond=prive/liste/formulaires_reponses}{id_formulaire}
	{titre=<:formidable:reponses_liste_publie:>}{ajax} />
 
<!--#navigation-->
<div class="cadre infos cadre-info">
	<div class="numero">
		<:formidable:voir_numero:>
		<p>#ID_FORMULAIRE</p>
	</div>
	<div class="hover">
		<a href="#SELF" class="cellule-h">
			[<img src="(#CHEMIN{images/formulaire-reponses-24.png})" style="vertical-align:middle;" alt="" />]
			<span style="vertical-align:middle;"><:formidable:reponses_liste:></span>
		</a>
	</div>
	<div>
		<a href="[(#URL_ECRIRE{formulaires_analyse}
			|parametre_url{id_formulaire, #ID_FORMULAIRE})]" class="cellule-h">
			[<img src="(#CHEMIN{images/formulaire-analyse-24.png})" style="vertical-align:middle;" alt="" />]
			<span style="vertical-align:middle;"><:formidable:reponses_analyse:></span>
		</a>
	</div>
</div>
<!--/#navigation-->
</BOUCLE_autoriser>
</BOUCLE_formulaire>

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 : 12/03/23

Translations : English, français