Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: Template Toolkit 2 and subroutines

by marcink (Monk)
on Oct 09, 2001 at 18:12 UTC ( [id://117739]=note: print w/replies, xml ) Need Help??


in reply to Re: Template Toolkit 2 and subroutines
in thread Template Toolkit 2 and subroutines

There are all kinds of things you CAN do in TT, but that doesn't mean you should do them.

I'm quite well aware of that, but thanks for reminding anyway ;)

What I want to do is really simple output processing (like substituting   for spaces in menus). I think that's something I can safely do in a template -- if not, I'll be happy to hear why before I go too far in a wrong direction :)

I checked merlyn's examples. Here are the results:

Template:

--cut here-- [% MACRO tr_test BLOCK %] join ':', @_; [% END %] [% PERL %] $stash->set( 'tr_test_2', sub { join ':', @_ } ); [% END %] 1: [% tr_test( 'test', '1' ) %] 2: [% tr_test_2( 'test', '2' ) %] --cut here--


And the result:

--cut here-- 1: join ':', @_; 2: test:2 --cut here--


So the latter does exactly what I need. Thanks for both answers.

-marcink

Replies are listed 'Best First'.
Re: Re: Re: Template Toolkit 2 and subroutines
by merlyn (Sage) on Oct 09, 2001 at 18:27 UTC
    What I want to do is really simple output processing (like substituting   for spaces in menus). I think that's something I can safely do in a template -- if not, I'll be happy to hear why before I go too far in a wrong direction :)
    Oh, then be sure to read Template::Filters to see how to do that properly. In fact, there might already be a filter in the standard collection to do that!

    -- Randal L. Schwartz, Perl hacker

Re: Re: Re: Template Toolkit 2 and subroutines
by davorg (Chancellor) on Oct 09, 2001 at 18:29 UTC
    What I want to do is really simple output processing (like substituting   for spaces in menus).

    Isn't that what FILTERs are for?

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."

Re: Re: Re: Template Toolkit 2 and subroutines
by perrin (Chancellor) on Oct 09, 2001 at 18:39 UTC
    In addition to the use of filters, you can pass a reference to any sub in as part of the stash. I sometimes pass in a URI escape subroutine from Apache::Util and use it like this in a template: [% uri(foo.bar) %]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://117739]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-19 03:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found