Hide commented code in PHP templates

A post cool for summer ;)

When working with php templates, such as using Drupal or WordPress, in which we introduce our variables directly the html using php, sometimes, especially when we are testing or changes requested by the client need to discuss some of the code, both php as html, so you can easily return to it and if something goes wrong.

We may be tempted to use html comment tags <! - And ->, this will hide what you do not want to see, but the php within the comments will continue running. This makes it more likely to appear in the new code errors besides altering the execution time and page load as we are processing the browser and sent items will not be shown.

The solution is so simple and elegant, just have to enter all the code (html and php) to comment within php comments

Here's an example:

  1. <Ul>
  2. <Li>
  3. $variable ? –> <! - Php echo $ variable? ->
  4. </ Li>
  5. </ Ul>

The form of serious comment:

  1. <? Php / *
  2. <ul>
  3. <li>
  4. <! - Php echo $ variable? ->
  5. </ Li>
  6. </ Ul>
  7. * /?>

This trail will not code in the content sent to the browser nor will consume runtime.

Relevant