How to deactivate part of a template?

All contributions published for previous SPIP versions

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
    // 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:


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.

updated on 1 July 2004


Aucune discussion

Ajouter un commentaire

Who are you?
[Log in]

To show your avatar with your message, register it first on (free et painless) and don’t forget to indicate your Email addresse here.

Enter your comment here

This form accepts SPIP shortcuts {{bold}} {italic} -*list [text->url] <quote> <code> and HTML code <q> <del> <ins>. To create paragraphs, just leave empty lines.

Add a document

Follow the comments: RSS 2.0 | Atom