Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by perrin (Chancellor)
on Aug 18, 2001 at 09:15 UTC ( [id://105885]=note: print w/replies, xml ) Need Help??


in reply to (elbie): Template Toolkit, and delaying the execution of a function
in thread Template Toolkit, and delaying the execution of a function

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.

  • Comment on Re: (elbie): Template Toolkit, and delaying the execution of a function
  • Download Code

Replies are listed 'Best First'.
(elbie 3): Template Toolkit, and delaying the execution of a function
by elbie (Curate) on Aug 20, 2001 at 21:47 UTC
    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://105885]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-16 17:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found