On 3/5/2010 10:20 AM, Jim Battle wrote:
>> Then your code would become:
>> ---------------------------------------------
>> [% SWITCH type %]
>> [% CASE 'text' %]
>> content
>> [% CASE 'css' %]
>> [% content | minimize_css %]
>> [% CASE %]
>> content WRAPPER html_wrapper.tt
>> [% END %]
>> ---------------------------------------------
>>
>> Note: I didn't test this, but it seems like a good/simple way to go
>> about it. Plus you can easily reuse the filter in the rest of your code.
>
> Josh -- thanks. In fact I tried that, and it was a subtopic of a later
> email. The problem was that the sub gets redefined on the 2nd and
> subsequent html pages and TT complains.
>
> Andy corrected speculated that declaring it as RAWPERL would fix it. In
> fact, it did.

Ok, sorry about that. The way I mentioned probably shouldn't have given you 
redefined errors, since it uses an anonymous subroutine. You probably could've 
done the same with yours as well without the need for RAWPERL.

For example:
      my $mycrunch = sub{
          use IPC::Run3 qw(run3);
          my $text = shift;
          my $output;
          run3 ['perl', 'lib/compact_css.pl'], \$text, \$output;
          return $output;
      };

      $context->define_filter(
          MyCrunch => $mycrunch,
      );


-- Josh

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

Reply via email to