We had this discussion last week. Please check the October mailing list
archives for information about this that should lead in you the right direction.
Here are the archives:
http://www.template-toolkit.org/pipermail/templates/
Here is the October list:
http://www.template-toolkit.org/pipermail/templates/2005-October/thread.html
Look for the messages with subject:
"arghhh, string replacement...help"
If you have access to the code, the first suggestion I made should help you.
However, now that I think of it, you may want to do this with a custom filter
rather than a vmethod, though.
ie. something like:
my $template_config = {
FILTERS => {
fix_brackets => sub {
my $value = shift;
# i changed your regexp here.
$value =~ s/\[([^\]]*)\]/@$1@/g;
return $value;
},
}
};
my $template = Template->new($template_config);
$template->process();
In your template just use:
[% value | fix_brackets %]
or
[% FILTER fix_brackets %]
This is [my] embeded [string]
[% END %]
-- Josh
Mark S. wrote:
Hello!
Regular expressions are a powerful part of Perl. However, I
can't seem to get the same power in the toolkit. When I try the
virtual function 'replace', it doesn't seem to have the ability
to identify groups (identified by parenthesis () ) and insert
them into the output text the way perl does.
That is, if I'm looking for embedded tags in a string like:
"This is [my] embeded [string]"
with Perl I could say
$text =~ s/[(.*?)]/@$1@/
and have the text become
"This is @my@ embeded @string@"
But the virtual function 'replace' doesn't seem to know how to
find groups and then insert them this way. Or maybe it does, but
the syntax isn't documented well enough.
When I try to do it using the PERL directive, I get a message
saying that it doesn't like the tilde (~) in the text:
! file error - parse error - xyz.html line 24:
unexpected token (~)
So it doesn't like the tilde in the =~ structure when used
inside of a PERL/END directive.
Is there any way to get the regular expression parsing of Perl
into the toolkit?
Thanks!
Mark
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates