Conditional displays

The charger() or traiter() functions can indicate if the form is editable or not in their responses. This provides a means of receiving an editable parameter in the template, which can be used to hide or display the form as desired (but not the error or success messages).

It is used like this [(#ENV{editable}) ... contents of the <form> ... ]:

<div class="formulaire_spip formulaire_demo">

	[<p class="reponse_formulaire reponse_formulaire_ok">(#ENV*{message_ok})</p>]
	[<p class="reponse_formulaire reponse_formulaire_erreur">(#ENV*{message_erreur})</p>]

	[(#ENV{editable})
		<form method='post' action='#ENV{action}'><div>
		#ACTION_FORMULAIRE{#ENV{action}}
		<ul>
		...
		</ul>
		<p class='boutons'><input type='submit' class='submit' value='<:bouton_enregistrer:>' /></p>
		</div></form>
	]
</div>

For any loops in the form

If there is a SPIP loop inside the code [(#ENV{editable}) ... ] (or any other tag), the SPIP compiler returns an error (or incorrectly displays the page) since this feature has not been envisaged in the current version of the template language.

To remediate this, you need to either:

  • put the loop in an include, and then call it using an <INCLURE{fond=mon/inclusion} />
  • or use the Bonux plugin and its CONDITION loop as follows:
    <div class="formulaire_spip formulaire_demo">
    
    	[<p class="reponse_formulaire reponse_formulaire_ok">(#ENV*{message_ok})</p>]
    	[<p class="reponse_formulaire reponse_formulaire_erreur">(#ENV*{message_erreur})</p>]
    
    	<BOUCLE_editable(CONDITION){si #ENV{editable}}>
    		<form method='post' action='#ENV{action}'><div>
    		#ACTION_FORMULAIRE{#ENV{action}}
    		<ul>
    		...
    		</ul>
    		<p class='boutons'><input type='submit' class='submit' value='<:bouton_enregistrer:>' /></p>
    		</div></form>
    	</BOUCLE_editable>
    </div>
    

Author Mark Baber Published : Updated : 12/03/23

Translations : English, Español, français