How to deactivate part of a template ?

Ceci est une ARCHIVE, peut-être périmée. Vérifiez bien les compatibilités !

Proper use of comments to debug or deactivate part of a template.

What’s the point of « commenting out » code ?

« Commenting out » to deactivate part of a template sometimes allows you to debug more effectively.

It also allows the template to be sent online when one part is not completed (this part is then « commented out »)... or just to put comments for those who will read it.

Comments in a script are important for you as well : in 6 months, you might have forgotten why you put that particular filter, while remembering that you had trouble getting the desired result.

Finally, still as a debugging tool, you can show some variables, verify their presence or their value... or simply verify that a section loop outputs the right sections : in the case of a loop that is used around an article listing loop, if your section loop doesn’t give the right results, the article loop will be wrong as well. (Of course, don’t forget to put back the comments)

As you can see, commenting out can be used for many purposes.

In Spip, it is possible to use needhave to know what you are going to comment out.

There are numerous interactions, so let me remind you that the order of execution is :

  1. Spip tags (loops, and #TEXTE...)
  2. PHP
  3. In the browser : HTML, javaScript and stylesheets.

To deactivate part of a template :

  • If it’s an HTML part, a simple HTML comment will be enough :
    <!-- 
    
    This is not interpreted by the browser (but it is by Spip)
    
    -->
  • For PHP :
    <?php # comment ?>
  • Or also
    <?php 
    
    // echo "This line isn't interpreted by PHP"; 
    
     ?>
  • And finally :
    <php /*  
    
    echo "This block and what follows is not interpreted...";
    
    echo "(Spip instructions are still interpreted by Spip..., don't forget to close them properly, but they won't show up.)";
    
    echo "...until";
    
    */ ?>
  • You can also try and destroy loops :

Remember that commented out Spip loops will still be interpreted by Spip, which can be a problem if you use the {doublons} or {unique} filter, in that case, you will have to break the loop (voluntarily writing wrongly the word BOUCLE in this way :

<B-OUCLE_art(ARTICLES){id_article}>
#TEXTE
</B-OUCLE_art(ARTICLES){id_article}>

Of course, you also have to do it for the closing tag, which is not very practical.

For the <INCLURE(...)> it’s simpler, as you only need to do :<IN-CLURE(...)>

Let me remind you once more that in a template, the order of interpretation is :

  1. Spip
  2. PHP
  3. HTML and JavaScript and... in the browser.

You are welcome to help complete this article.

Discussion

Aucune discussion

Ajouter un commentaire

Avant de faire part d’un problème sur un plugin X, merci de lire ce qui suit :

  • Désactiver tous les plugins que vous ne voulez pas tester afin de vous assurer que le bug vient bien du plugin X. Cela vous évitera d’écrire sur le forum d’une contribution qui n’est finalement pas en cause.
  • Cherchez et notez les numéros de version de tout ce qui est en place au moment du test :
    • version de SPIP, en bas de la partie privée
    • version du plugin testé et des éventuels plugins nécessités
    • version de PHP (exec=info en partie privée)
    • version de MySQL / SQLite
  • Si votre problème concerne la partie publique de votre site, donnez une URL où le bug est visible, pour que les gens puissent voir par eux-mêmes.
  • En cas de page blanche, merci d’activer l’affichage des erreurs, et d’indiquer ensuite l’erreur qui apparaît.

Merci d’avance pour les personnes qui vous aideront !

Par ailleurs, n’oubliez pas que les contributeurs et contributrices ont une vie en dehors de SPIP.

Qui êtes-vous ?
[Se connecter]

Pour afficher votre trombine avec votre message, enregistrez-la d’abord sur gravatar.com (gratuit et indolore) et n’oubliez pas d’indiquer votre adresse e-mail ici.

Ajoutez votre commentaire ici

Ce champ accepte les raccourcis SPIP {{gras}} {italique} -*liste [texte->url] <quote> <code> et le code HTML <q> <del> <ins>. Pour créer des paragraphes, laissez simplement des lignes vides.

Ajouter un document

Suivre les commentaires : RSS 2.0 | Atom