Re: [htmltmpl] die_on_missing_params
Brought to you by:
samtregar
From: Mathew R. <mat...@ne...> - 2007-06-15 02:38:10
|
Hi List, [ Eventually I will post a patch to H::T to a webpage, in the meantime I have sent an update version directly to Joshua. If others are interested in this patch, shoot me a email. ] > I am happy to say that I haven't run into any problems using Mathew's > patch. It's exactly what I wanted/needed! Thanks! > Thats good. > I do have a feature request though: > > Currently if I leave out 2 params, it only notifies me that one of > them is missing. It would be nice if I was told when both were > missing. > Hadn't considered that. The existing coding practice within H::T is that is croak's immediately on error conditions. However, in the case of this option, adding support for accumulating the errors is pretty trivial, so I did. > This issue applies to die_on_bad_params as well, but it's slightly > more subtle, because the dying point is different. With > die_on_bad_params, you die as soon as the param is set, so no list of > bad_params could accumulate. (unless of course you wait until > $template->output() to die). > > Also, I've noticed that if I comment out a <tmpl_var ...> in the > template file, die_on_missing_params still thinks I should set it. > Likewise, if I set a parameter that has been commented out, > die_on_bad_params remains silent. Perhaps this is the intended > behavior... after all, somebody may want to fill in html comments from > the code. And adding a new comment syntax to template files would > detract from it's great simplicity. Besides, commenting out code is > considered bad practice anyway, isn't it? :) > Some browsers support conditional compilation/execution, which means that HTML comments are actually parsed. In fact, since HTML comments are true-dinks DOM elements, there are some javascript libraries that parse the comment block to enable extra features, while being old-browser compatible. So yes, you want TMPL_xxx parsed inside HTML comments. If you really want to comment out a TMPL_VAR, you could try unsetting "strict" so that you can do: <TMPL_VAR name> => <TMPL_ZUH name> Or if you need to comment out a HTML block, you can use a H::T filter such as: sub tmpl_comment { my $filter = sub { my $text_ref = shift; my $match = qr/<(?:\!--\s*)?[Tt][Mm][Pp][Ll]_[Cc][Oo][Mm][Mm][Ee][Nn][Tt]\s*(?:--)?>.*?<(?:\!--\s*)?\/[Tt][Mm][Pp][Ll]_[Cc][Oo][Mm][Mm][Ee][Nn][Tt]\s*(?:--)?>/s; $$text_ref =~ s/$match//g; }; return $filter; } $ht = HTML::Template->new(...., filter => tmpl_comment,...); <TMPL_COMMENT> ... some <a...> html </a> </TMPL_COMMENT> Regards, Mathew Robertson |