[htmltmpl] Fun with Filters.
Brought to you by:
samtregar
From: Jeff P. <jp...@gr...> - 2003-08-13 15:03:50
|
Howdy! I'm having a time using filters and not sure if what I am doing is wrong (if anything). I am just using the sample in the documentation. I should also mention the standard caveats: I searched the Archives first and the examples looked like mine. Also, I should mention that I am using Win2K and IIS 5. I am not sure if this is the issue again or not. I receive a 200 header status and no output from debug. Another ?: Can you create a filter to deal with form/user input too? Is that what the "removing_spaces" filter in the documentation is meant to do? YA?: What does the "$$" mean in $$test_ref. I know that $$ is used to retrieve the process number. I looked in the documentation and several Perl Books including "Programming Perl" but did not find a reference to this in the book. Thanx, Jeff. PS - The function(s) work fine and I could just use them instead. I just wanted to see what a filter did and what you could do with them. Anyway, here is the code: my $filter = sub { my $text_ref = shift; $text_ref =~ s/!!!ZAP_(.*?)!!!/<TMPL_$1>/g; $$text_ref; ## Also Tried Adding "return $text_ref;" - No Difference. }; sub test_function { ##my $str1 = shift; my ($str1, $str2) = @_; my $strTest = qq~Hi this is some text: '$str1-$str2'.~; return $strTest; } my $tmpl = HTML::Template::Expr->new( filename => 'filter2.tmpl', die_on_bad_params => 0, associate => $cgi, filter => $filter, functions => { test_func => \&test_function }, debug => 1 ); $tmpl->param( FOO => 'Try My Filter!~#$%'); Here is the Template portion: Howdy: !!!ZAP_VAR NAME="FOO" !!!.<BR> Here is the result displayed by the browser: Howdy: !!!ZAP_VAR NAME="FOO" !!!. __END__ CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information, the disclosure of which is governed by applicable law. If the reader of this e-mail is not the intended recipient(s), any unauthorized review, use, disclosure or distribution is prohibited. If you have received this message in error, please contact the sender by reply e-mail and destroy all copies of the original message immediately. |