Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Commenting out code in templates


Go to End


4 Posts   9193 Views

Avatar
david_nash

Community Member, 55 Posts

20 February 2009 at 2:24pm

Hi, my name's David - I'm new here :-)

I've installed Silverstripe and I'm so impressed that I'm using it for two sites I'm doing at the moment. I'm playing around with templates and want to know if it's possible to comment out code.

I can use HTML's <!-- --> but the template code still gets processed.

I'm looking at the BrightSide1 template which spews out errors if you don't have a page called 'Blog'. I want to comment out that code, in the .ss file so I can refer to it later. Is this possible?

My apologies if there's some reference somewhere that explains this - I searched through the docs and the forums and couldn't find anything.

Thanks in advance,
David.

Avatar
Fuzz10

Community Member, 791 Posts

22 February 2009 at 2:29am

Welcome to Silverstripe ! Good choice ! ;-)

That is a good question .. I remember there was talk about this some time ago...

Kinda' forgot wat the outcome was..but AFAIK it has not been implemented yet. ;)

Avatar
david_nash

Community Member, 55 Posts

22 February 2009 at 12:34pm

Thanks fuzz, I appreciate it!

I've had a cursory look at parseTemplateContent() in sapphire/core/SSViewer.php , and I can see where it's processing the <!-- --> - I don't think it'd be too hard to modify my own version so that the stuff inside html comments doesn't get processed.

I know comments are nothing huge and I could just make a backup of the template file, but I find it helpful to comment out code when I'm learning something new, it helps me pinpoint where my bugs are.

thanks again :-)

Avatar
inCharge

Community Member, 102 Posts

18 September 2011 at 11:08pm

Edited: 18/09/2011 11:09pm

It's documented here: http://doc.silverstripe.org/sapphire/en/reference/advanced-templates#comments

Comments in .ss files like this...

<%-- this is a comment --%>

...must have the start & end tags on the same line, so this will not work...

<%--
<p>comment this out temporaily for debugging purposes</p>
<div>and this too etc...</div>
--%>

...which is a pity. It would be useful.