Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Template Toolkit, and delaying the execution of a function

by echo (Pilgrim)
on Aug 18, 2001 at 15:02 UTC ( #105902=note: print w/replies, xml ) Need Help??


in reply to Template Toolkit, and delaying the execution of a function

I see no reason in your code to delay execution of show_elements. You can just change that sub to return a list of stuff, instead of having it output HTML items directly (which is the whole point of using templates in the fist place):
sub show_elements ($)
{
    my $num = $_[0];
    return [] unless( $num > 0 );
    return [ 1..$num ];
}
...
my $data = {
             show_elements => show_elements( $elements ),
           };
then in the template:
<ul>
{# FOREACH e = show_elements #}
  <li>{# e #}</li>
{# END #}
</ul>

If you really need to delay the sub call, have a look at the TT docs which explain it quite adequately.

  • Comment on Re: Template Toolkit, and delaying the execution of a function

Replies are listed 'Best First'.
(elbie 2): Template Toolkit, and delaying the execution of a function
by elbie (Curate) on Aug 18, 2001 at 18:38 UTC
    You're not the first person to suggest changing the subroutine. I'd like to clarify that that is exactly the thing which I was hoping to avoid.

    The example I gave above was a rather simplified example. Some of the subroutines are rather long and complex, and with the current allotment of time, it's not feasible.

    Any new stuff we will write will certainly take advantage of all the fine features that the TT has to offer, but for the existing stuff, I need something quick and dirty.

    dondelecaro suggested IO::Scalar which seems promising, and I like perrin's suggestion as well. I'll try out both of those.

    elbieelbieelbie

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2021-12-04 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (30 votes). Check out past polls.

    Notices?