4

This is a very simple question but it has irritated me. I would like to comment the following for example:

<!--  
        {if $scenes}
            <!-- Scenes -->
            {include file="$tpl_dir./scenes.tpl" scenes=$scenes}
        {else}
            <!-- Category image -->
            {if $category->id_image}
            <div class="align_center">
                <img src="{$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category')}" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" width="{$categorySize.width}" height="{$categorySize.height}" />
            </div>
            {/if}
        {/if}
    -->

I would like to comment out all this text, so the browser won;t display this code. The problem is that I have already comments and it seems that the browser confuses the end tag. Therefore in this case the first opening comment tag only would affect {if $scenes} when I would wish it affects the entire text. Could you let me know how can this be done?!?!

Thanks,

Dani

Mohamad
  • 34,731
  • 32
  • 140
  • 219
Daniel Ramirez-Escudero
  • 3,877
  • 13
  • 43
  • 80
  • 2
    See http://stackoverflow.com/questions/442786/are-nested-html-comments-possible – bmb Aug 06 '12 at 23:05
  • 2
    My solution: don't (because it's not supported in SGML/HTML/XML) .. use a DVCS and/or other "history" ;-) That being said, perhaps the engine/template has an alternative comment that can be used? In ASP.NET, for instance, `<%-- This is a comment that doesn't even get into the HTML output --%>` –  Aug 06 '12 at 23:14

2 Answers2

3

If I understand you correctly, you want to be able to nest your HTML comments. In order to do this you need to replace double dash -- with a two single dashes and a space - -.

Basically,

<!--
  This is a comment.
  <!- - 
    This is a nested comment.
  - ->
-->

Applying this to your code, you should end up with something like this:

<!--  
        {if $scenes}
            <!- - Scenes - ->
            {include file="$tpl_dir./scenes.tpl" scenes=$scenes}
        {else}
            <!- - Category image - ->
            {if $category->id_image}
            <div class="align_center">
                <img src="{$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category')}" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" width="{$categorySize.width}" height="{$categorySize.height}" />
            </div>
            {/if}
        {/if}
    -->
Mohamad
  • 34,731
  • 32
  • 140
  • 219
  • 1
    +1 Although, it misses some details (e.g. why is it `- -`?) and, to be fair, this is not nesting .. this is keeping the [new] comment from being an invalid comment. –  Aug 06 '12 at 23:16
  • 1
    Thanks, this answers my questions perfectly. Maybe its not nesting... I'm not so good with the exact terminology. Thanks Mohamad, as we say in Spain, clear as water! – Daniel Ramirez-Escudero Aug 14 '12 at 21:58
  • You actually don't have to put a space in between the double dashes. When you do put a space after the first dash it is an invalid comment, it's actually considered a "bogus" comment. The reason it works as a comment and doesn't close the previous comment is because it's rendered in as a comment token afterwards. – Andrew Sep 25 '16 at 21:32
1

The language you have there isn't HTML, but a language which generates HTML. The language obviously supports if/else conditionals which nest, since you show a very example of that. So even if the HTML-generating language itself lacks nesting comments, you can use conditionals to remove sections of it from being executed, therefore suppressing the generation of that HTML:

Suppose the token false represents a boolean false (substitute the correct expression for false in the given template language):

{if false}
    {if $scenes}
    <!-- ... >
    {else}
    ...
    {/if}
{/if}

Everything in the if false block is excluded from being output by the processor.

Kaz
  • 55,781
  • 9
  • 100
  • 149