Jump to:

3447 Posts in 1032 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » Commenting out code in templates

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

Page: 1
Go to End
Author Topic: 2551 Views
  • david_nash
    Avatar
    Community Member
    55 Posts

    Commenting out code in templates Link to this post

    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.

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: Commenting out code in templates Link to this post

    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. ;)

  • david_nash
    Avatar
    Community Member
    55 Posts

    Re: Commenting out code in templates Link to this post

    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

  • inCharge
    Avatar
    Community Member
    102 Posts

    Re: Commenting out code in templates Link to this post

    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.

    2551 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.