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.

Dernière modification de cette page le 1er juillet 2004

Discussion

Aucune discussion

Ajouter un commentaire

Qui êtes-vous ?

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