If I want to remove parts of .tpl.php file what are my options other than removing them permanently? HTML comments < !-- --> work but print the part in the HTML source. PHP // comments or /* */ don't work.

For example, how could I comment out a block like:

    <?php if ($logo): ?>
      <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo">
      <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
      </a>
    <?php endif; ?>
link|improve this question

2  
How long are these removals left in your code? Only during active development or indefinitely? IMHO, comments are fine for a few quick tests, but to avoid bloat and debugging headaches I would look into version control as @tim.plunkett suggested. – Citricguy Nov 13 '11 at 1:06
good point. I'm using git for development, I'm just not too familiar with it yet where I can quickly see the history of changes on a file. – MotoTribe Nov 13 '11 at 3:46
Maybe not the greatest solution, but if your GUI has a local history, that could work for your local comparisons. You can still use git as well and when you're ready to dive into it, your info will all be there. :) – Citricguy Nov 13 '11 at 5:10
feedback

3 Answers

up vote 4 down vote accepted

I actually prefer to use this way

<?php if (FALSE): ?>
<div class="meta">
  <?php if ($submitted): ?>
    <span class="submitted"><?php print $submitted ?></span>
  <?php endif; ?>

  <?php if ($terms): ?>
    <span class="terms"><?php print $terms ?></span>
  <?php endif;?>
</div>
<?php endif; ?>

This make it easier to put the block back in (change FALSE to TRUE), or attach a variable to the conditional.

EDIT:

To address your example, I would do it one of two ways

<?php if (FALSE): ?>
<?php if ($logo): ?>
  <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo">
  <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
  </a>
<?php endif; ?>
<?php endif; ?>

or

<?php if (FALSE && $logo): ?>
  <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo">
  <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
  </a>
<?php endif; ?>

I would normally lean towards using the second in my daily work.

link|improve this answer
feedback

Use version control, and then you can just delete the lines.

link|improve this answer
feedback

Anything within PHP tags can be commented with // or /* */

Are you missing any opening or closing PHP tags?

link|improve this answer
I added an example to my question – MotoTribe Nov 12 '11 at 23:11
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.