On Sunday, October 26, 2003, at 10:30 AM, Cees Hek wrote:


Quoting Puneet Kishor <[EMAIL PROTECTED]>:

While templates are supposed to be (almost) pure html, I want to insert
comments in the templates (for my benefit... all those loops within
loops get confusing after a while) that I don't want printed in the
browser. Would be nice to have some kind of meta template comment tag
that is stripped out while filling the templates on the server.
Something like --


There are a couple of ways to do this already:

First, just use a TMPL_IF construct that is always false:

<TMPL_IF NAME="comment">
THis is a comment as long as the code never defines the variable 'comment'
</TMPL_IF>


or you could write a simple filter that strips out all your comments when you
load the template:


my $filter = sub {
      my $text_ref = shift;
      $$text_ref =~ s/\<\<\!\-\-.*?\-\-\>\>//g;
};

my $template = HTML::Template->new(filename => $template_file,
                                     filter => $filter);


The second one is probably preferrable, but I would use something besides <<! >>
as the delimiters, Since they are not valid HTML, and also they are not easily
distinguishable from regular comments. Why not something like <!--SRV Here is a
server side comment -->




very nice... thanks for the tip. I will use


<!--# this is a server side comment -->

so my code editors will still colorize the comments as comments, it will remain valid html, and the # is, well, a recognizable server side comment.

cool.



-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to