Jump to content

Printing HTML comments in final output


Recommended Posts

Hi,

 

Example, I am trying to print out a HTML comment in the generated HTML / TPL file.

 

<!--googleoff: snippet--> abc123 <!--googleon: snippet-->

 

But Smarty somehow truncates the comment.

 

Purpose is to prevent Google from indexing some content on my page.

Link to comment
Share on other sites

Hi,

 

Example, I am trying to print out a HTML comment in the generated HTML / TPL file.

 

<!--googleoff: snippet--> abc123 <!--googleon: snippet-->

 

But Smarty somehow truncates the comment.

 

Purpose is to prevent Google from indexing some content on my page.

 

 

try with {literal} CODE HERE {/literal} tags

 

im not sure, maybe this wont work. I think that the problem is somewhere else

Link to comment
Share on other sites

  • 1 year later...

I have exactly the same issue.

 

I can make any changes in the header.tpl and they show up just fine in the page source after i make the change (i have force compile On and Cache Off).

 

However, if i add <!--googleoff: snippet--> abc123 <!--googleon: snippet--> it does not work. The comments are just removed, is like they don't exist in the header.tpl code.

 

I also tried {literal}<!--googleoff: snippet-->{/literal} but it still does not show...

Link to comment
Share on other sites

Ok, i made some progress :)

 

The issue is caused by "Compress HTML" option from Advanced settings > Performance. If that is set to ON, all html comments are stripped from <body>

 

Does anyone knows how to avoid that? I assume some core files might be changed... i want to Compress HTML but keep the comments.

Link to comment
Share on other sites

It's not easy if you don't know regex. You must edit

 

tools\minify_html\minify_html.class

 

You might be able to get away by just commenting out this

 

 

        // remove HTML comments (not containing IE conditional comments).
        $this->_html = preg_replace_callback(
            '/<!--([\\s\\S]*?)-->/'
            ,array($this, '_commentCB')
            ,$this->_html
            ,Media::getBackTrackLimit());
        
 
But I didn't test it
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...