2009/12/21 Octavian Râşniţă <[email protected]>

> Hi,
>
>    Is there a filter for TT that gets an HTML string as input and returns
> the text outside of the HTML elements?
>
> Something like:
>
> [% "<b>text</b>" | TheFilter %]
>

How about a quick vmethod?

use Template;
use HTML::Strip;  # no idea how good this is
use strict;
use warnings;

my $tt = Template->new;
$Template::Stash::SCALAR_OPS->{ strip_html } = sub {
    my $hs = HTML::Strip->new;
    my $clean_text = $hs->parse( shift );
    $hs->eof; # huh?
    return $clean_text;
};

my $template = <<'EOF';
[%
    my_html = '<b>bold text</b>';
%]
Stripped = [% my_html.strip_html %]
EOF

$tt->process( \$template );


Returns:

 Stripped = bold text



-- 
Bill Moseley
[email protected]
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to