Nicole Haines Nicole Haines - 4 months ago 20
HTML Question

Commenting out Content - HTML and PHP

I am currently tweaking a BigCommerce theme for my employer. They have asked me to remove and change a few CSS / HTML elements to fit the style and functionality that they are after.

Rather than just DELETING the functionality within the theme, I was hoping to just comment it out in case it is needed later. But I am having an issue with the formatting.

The following is the code as displayed in the ProductDetails.html Panel file:

<div class="Content" id="prodAccordion">
%%Panel.ProductTabs%%
%%Panel.ProductDescription%%
%%Panel.ProductVideos%%
%%Panel.ProductWarranty%%
%%Panel.ProductOtherDetails%%
%%Panel.SimilarProductsByTag%%
%%Panel.ProductReviews%%
%%Panel.ProductByCategory%%
%%Panel.SimilarProductsByCustomerViews%%
</div>


I am trying to comment out the last 3 lines only.

However, when I do, the end of the comment ( --> ) shows up in the browser. I have closed the comments correctly but there must be some simple concept that I am missing. Hoping the good people at SO can help.

Below is the code as I have saved it and a screenshot of the display in my browser. The first screen shot is how it looks before I add any comments and the second is after I add them. You can clearly see the closing comment in the second image, can anyone tell me why??

Thanks in advance for any help.

<div class="Content" id="prodAccordion">
%%Panel.ProductTabs%%
%%Panel.ProductDescription%%
%%Panel.ProductVideos%%
%%Panel.ProductWarranty%%
%%Panel.ProductOtherDetails%%
%%Panel.SimilarProductsByTag%%
<!--%%Panel.ProductReviews%%-->
<!--%%Panel.ProductByCategory%%-->
<!--%%Panel.SimilarProductsByCustomerViews%%-->
</div>


Before

After

Answer

Nicole, I've dealt with this and can definitely explain why it's happening and how to avoid it.

Why It's Happening

It's happening because this is how BigCommerce's server side PHP processor parses the code you're looking at. The code is basic HTML, while the %%Panel.something%% are simply ways for BigCommerce's processor to recognize as a command for BigCommerce.
Anytime the BC site sees %%Panel.Name%%, it knows that this is not HTML, but rather a place where BC server-side processor should insert the Panel file before serving this HTML to the user.

How to Avoid it and Comment-out Correctly

Simply, remove the % symbols and use regular commenting. This will work:

 <!-- Panel.ProductReviews-->

So will this:

 <!--%%Panel.ProductReviews-->

And this:

  <!-- Panel.ProductReviews%%-->

Or even this:

  <!-- %Panel.ProductReviews% -->

Mainly, you have to make sure that each side of a Panel.Name reference, doesn't have 2 % symbols on each side.

To Restore the Correctly Commented Out Code/Panel

Simply restore the 2 % symbols on each side like so (the spaces between - and % don't matter, you can have none or 10):

  <!-- %%Panel.ProductReviews%% -->

Why You're Seeing --> On Live Site

As broached/explained in the comments of your question, you're seeing --> when commenting out a Panel like so <!--%%Panel.Name%%--> because by commenting out the Panel that way without removing at least one of the % symbols, you're still telling BigCommerce to load the Panel HTML file, but to place it within the

<!-- [HTML code from panel goes here] -->

The problem with that is simply that some of these Panel files contain comments themselves. For example, let's say you comment out %%Panel.Header%% like so !<--%%Panel.Header%%-->. The Header.html Panel may be code like this:

<!-- this is the header code panel-->
<div class"MainHeader">
     <ul class="TopNav">
         ...
     </ul>
</div>

By commenting out the code without removing the % symbols, BigCommerce will load this:

<!--
<!-- this is the header code panel-->
<div class"MainHeader">
     <ul class="TopNav">
         ...
     </ul>
</div>
-->

when a user open a page that uses the Header.html panel, they will see this code as commented <!--<!-- this is the header code panel-->, because the browser will start the comment at the first <!-- and end the comment at the first appearance of -->.

In the browser, the user will see the uncommented remains:

<div class"MainHeader">
     <ul class="TopNav">
         ...
     </ul>
</div>
-->

And hence you'll see some extra, probably broken HTML, plus the stray --> somewhere at the end of the improperly commented code.

Again, to avoid all this, just remove one of the % symbols, then use regular commenting to comment out a Panel file reference.

Let me know if this helps and if you have any other questions.