MMv4 KB
 
Using comments in Custom QuickCode Tags
  Last Edited - 02/24/2012 4:15pm PST
  Category Path - Shopping Cart Software Components > Administration Area > Design > FAQs & Tutorials
 
Comments are statements within code (webpage HTML, PHP code, JavaScript, etc.) that are not executed or displayed.  They are very useful when creating webpages, so here's a short tutorial on what they are, how to use them, and how they affect QuickCode™ tags.
 
What is a Comment?

Comments are strings of text within code that are not meant to be executed or displayed when a web page is rendered in a browser. They are prefixed or enclosed by certain characters so that the browser knows that it should ignore them, and the characters that are used depends on the programming or scripting language that you are using. 

In HTML, comments are enclosed in the tags "<!--" and "-->", while in PHP, a comment can be prefixed by "//" or enclosed by "/*" and "*/".  Here are some examples of comments.

html comments
<!-- This is a comment! -->
Lions and tigers and bears, oh my!
<!-- This is another comment! -->
Lions and tigers and bears!

php comments
<?php
// echo "This is a comment! "
echo ("Lions and tigers and bears, oh my!");
/* echo "This is another comment!" */
echo ("Lions and tigers and bears!");
?>

In both cases, the code will display only the lines about lions and tigers and bears.  Since text and commands within comments are not displayed or executed, none of the statements about comments will be seen by the user.

did you see that?
HTML comments will be present in a web page's source code.
PHP comments will not.

 
How Should I Use Comments?

Comments are used primarily to document code; as the name implies, programmers use comments to leave comments about what the code is intended to do.  This makes it a lot easier for you to remember what the code does when you, or someone else, come back to it months or years later.  It's a good idea to be as explicit as possible in your descriptions, because it will save you time and hassle in the long run.

The second common use for comments is to deactivate code that you no longer need. Placing comment tags around blocks of code removes them from the execution of the page, but preserves it, in case you want re-insert it later.  You can also use comments temporarily, while troubleshooting a problem, to remove working code and isolate the code that is causing the problem.  Once the problem is fixed, you can remove the comment tags to reinstate all of the working code on the page.
 
Can I use comments to deactivate custom QuickCode Tags?

The short answer is yes!  Simply encapsulate the custom QuickCode Tag's contents within the appropriate comment tags to turn it off.

deactivating content within a custom quickcode tag
<?php
/*
This content is within a comment.
None of this code within the comment will be executed.
echo ("Lions and tigers and bears, oh my!");
echo ("Lions and tigers and bears!");
*/
?>

Powered by ModularKB