Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

(elbie): Template Toolkit, and delaying the execution of a function

by elbie (Deacon)
on Aug 18, 2001 at 06:40 UTC ( #105867=note: print w/ replies, xml ) Need Help??


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

Yup, and that's exactly the problem. What I'm hoping is that there is some way to delay the execution of the subroutine, or to encapsulate the subroutine in another function that redirects the output to a variable.

I can't seem to find the module Template::Perl anywhere though. :(

elbieelbieelbie


Comment on (elbie): Template Toolkit, and delaying the execution of a function
Re: (elbie): Template Toolkit, and delaying the execution of a function
by perrin (Chancellor) on Aug 18, 2001 at 09:15 UTC
    It would be cleaner to change you code to return values, but TT does provide a directive that automatically ties STDOUT for you. Try this:

    {#PERL#} $stash->get('show_elements'); {#END#}

    Or just call &show_elements in some other way from within the PERL block.

      I tried a couple of different things with Template::Stash to get the output of the subroutine, but all seem to result in STDOUT from the subroutine to print at the top of the page.

      Here's my modified code:

      my $tmpl_stash = Template::Stash->new( { 'show_subcat' => \&show_subcat( $lpmkey ), } ); my $tmpl_data = { "${lpmkey}select" => ' selected', # 'show_subcat' => show_subcat( $lpmkey ), 'lpmcat' => $lpmkey, 'lpmcategory' => { 'l' => 'Logos', 'p' => 'Photos', 'm' => 'More', }->{ $lpmkey }, };

      And then I have a <code>{#PERL#} block like you suggested in your post. I also just tried running the subroutine from the block directly, avoiding using Template::Stash, but I'm still running into the same problem.

      Any help would be appreciated.

      elbieelbieelbie

        Drat! That should have worked.

        Well, actually, in the first case you don't need to put that specially in the Stash. You should be able to pass it in with the other data when you call process().

        It really should work when you call it directly from within a PERL block though. Are you doing anything with STDOUT in your sub?

        At this point, you might want to post to the TT mailing list and ask why the PERL block isn't working. I'm pretty sure it's supposed to work for exactly this case. You can find the mailing list at http://template-toolkit.org/.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-07-26 17:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls