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 :
- Spip tags (loops, and
#TEXTE
...) - PHP
- 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 :
- Spip
- PHP
- HTML and JavaScript and... in the browser.
Aucune discussion
Ajouter un commentaire
Avant de faire part d’un problème sur un plugin X, merci de lire ce qui suit :
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.
Suivre les commentaires : |