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

Re: Callbacks and templates.

by davorg (Chancellor)
on Apr 13, 2004 at 01:57 UTC ( [id://344630]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Callbacks and templates.

The Template Toolkit can use callbacks. I'm not sure exactly what you want to do, but this demonstrates the general idea.
#!/usr/bin/perl + use strict; use warnings; use Template; + my $tt = Template->new; + my $data = { word => 'callbacks', emphasise => \&emphasise }; + $tt->process(\*DATA, $data) || die $tt->error(), "\n"; + sub emphasise { return "** @_ **"; } + __DATA__ This is a template. It includes [% emphasise(word) %]
--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re: Re: Callbacks and templates.
by LukeyBoy (Friar) on Apr 13, 2004 at 03:17 UTC
    That looks great, thanks!
Re(2): Callbacks and templates.
by bart (Canon) on Apr 13, 2004 at 05:13 UTC
    I didn't know you could do it this way. Neat.

    Anyway, TIMTOWTDI, even for Template-Toolkit. Here's the same demo modified to use a filter, which is like a "program" (thus, a sub) you pipe the data through.

    #!/usr/bin/perl -w use strict; use warnings; use Template; my $tt = Template->new(FILTERS => { emphasise => \&emphasise }); my $data = { word => 'callbacks' }; $tt->process(\*DATA, $data) || die $tt->error(), "\n"; sub emphasise { return "** @_ **"; } __DATA__ This is a template. It includes [% word | emphasise %]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://344630]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.