Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

Does anyone else experience issues with their templates when they nest code comments?

I've inherited a project with some code already commented like this

code code code
code code code
{!-- ... some code here ... --}
code code code
code code code

Then I've come along and commented more code out like this:

code code code
{!--
code code code
{!-- ... some code here ... --}
code code code
--}
code code code

Only to find that the templates completely break.

So i've ended up doing something similar to this:

code code code
{!--
code code code
<!-- ... some code here ... -->
code code code
--}
code code code

Which isn't ideal if I ever come back to this code as it has a completely different (undesired) effect.

Is there something I'm missing here?

share|improve this question
    
Why not just move the opening and closing comment tags? I don't think there's a way around this due to the way the template parser works. –  Jeremy Gimbel Mar 6 at 16:22
2  
Unfortunately it is not possible to nest comments –  CreateSean Mar 6 at 16:51
    
@CreateSean thought so. just wanted to check –  Simon Mar 6 at 17:11

3 Answers 3

Yes, ExpressionEngine comments stop at the next --} that they find. It's quite irritating.

The rule of thumb I use is to use HTML comments for notes about the frontend code, and ExpressionEngine comments about the EE code. That tends to eliminate the problem most of the time.

Sometimes I just cut + paste blocks of code into other documents while I'm debugging and put them back in later on.

share|improve this answer
    
Thanks for the suggestion. That's a workable solution for now. Just caught me by surprise as there's no clear documentation/prohibition from EllisLab. –  Simon Mar 6 at 17:12

You can't actually nest comment blocks.

In PHP you wouldn't be able to nest a /* */ within itself, nor would you be able to nest comments in HTML <!-- <!-- --> -->, but you could try adding spaces arbitrarily in between for personal notes of where comment blocks used to be. Could be useful if it's a snippet of code you may need to reintroduce later or in a similar template, or just to say something.

E.g.

{!--
code code code
{!- - ... some code here ... - -}
code code code
--}

If you're going to go an arbitrary route you can really do whatever you want within a comment block. I use Coda 2 as my editor, I can edit multiple lines simultaneously and just prefix single line comments. In PHP it'd be //, but since everything is ultimately enclosed in a comment block you could just do whatever, though you'll have to bear in mind... they're not actually comments on their own.

share|improve this answer
1  
You're absolutely right... not quite sure why I expected EE comment nesting to be acceptable... feeling pretty stupid now. –  Simon Mar 7 at 11:33
    
No worries, wasn't what I was trying to highlight. An EE comment may have felt like an EE tag, so it's understandable. –  notacouch Mar 8 at 2:13
up vote 1 down vote accepted

So as has been mentioned in the comments on this post, it's not possible to nest EE's template code comments.

It results in unexpected behaviour. So if like me you suddenly and unexpectedly lose all output from a template, check that you haven't got nested comments.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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