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

Re^3: Evaluating subroutines from within data

by Anonymous Monk
on Jan 08, 2012 at 00:57 UTC ( [id://946813]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Evaluating subroutines from within data
in thread Evaluating subroutines from within data

graff, I have looked at both of those modules, and neither would do the templating I need for my site

Those are brave words, I highly doubt TT2 wouldn't be able to accomplish what you need :)

For example

print_definitions( file => "some_file_a.txt", headings => [ "term", "definition" ], )

in tt2 you could write as

[% INCLUDE print_definitions.tt file = "some_file_a.txt" headings = [ "term", "definition" ] content = "this ends up in variable content " %]

Or even as

[% WRAPPER print_definitions.tt file = "some_file_a.txt" headings = [ "term", "definition" ] %] this ends up in variable content [% END %]

See http://search.cpan.org/perldoc/Template::Manual::Directives#INCLUDE,

http://search.cpan.org/perldoc/Template::Manual::Directives#WRAPPER

http://search.cpan.org/perldoc/Template::Tutorial::Web

Replies are listed 'Best First'.
Re^4: Evaluating subroutines from within data
by Lady_Aleena (Priest) on Jan 08, 2012 at 02:45 UTC

    Are you saying that I'd have to break up all of my modules and put the subroutines into their own files with a .tt extension? So, I'd have to break up my Base::HTML where most of the base code for my site lives?

    Have a cookie and a very nice day!
    Lady Aleena

      Are you saying that I'd have to break up all of my modules and put the subroutines into their own files with a .tt extension? So, I'd have to break up my Base::HTML where most of the base code for my site lives?

      :| Are you calling me Shirley? |:

      :|

      Note the lack of humor in my facial expression ;D

      Organizing templates in separate files is the most natural way to do it, but you're not limited to that approach

      When you said tt2 would not do the templating you need, I assumed you couldn't find the argument passing portion of the manual, so I showed you a simple example, was I wrong?

      If you wish to use Base::HTML from TT2 you could make a plugin

      [% USE BaseHTML; # Template::Plugin::BaseHTML.pm GET BaseHTML.print_definitions( file => "some_file_a.txt", headings => [ "term", "definition" ], ); %]

      Here is a running example

      $ cat dumper.tt [% USE Dumper Indent = 1; GET Dumper.dump( file => "some_file_a.txt", headings => [ "term", "definition" ], ) %] $ tpage dumper.tt $VAR1 = { 'file' => 'some_file_a.txt', 'headings' => [ 'term', 'definition' ] };

      Or you could use the Class plugin, simple running example

      $ cat class.tt [% USE q = Class('CGI'); GET q.start_form(); %] $ tpage class.tt <form method="post" action="http://localhost" enctype="multipart/form- +data">

      If the OOP-yness of Template::Plugin::Class doesn't quite work for you (since your base doesn't appear to be OO), its easy to modify to Template::Plugin::Class::Proxy::AUTOLOAD to remove $self

      See also Template::Plugin, Template::Plugin::, Template::Plugin::Dumper, , Template::Plugin::Class, Template::Provider::Preload, Template::Provider::MD5, Template::Provider::Memory

        I might give all of that a look later as soon as I figure out how to achieve what I wanted to originally. I have a full example of what I want to do in Re^2: Evaluating subroutines from within data if you care to take a look. From the looks of it, I would have to start almost from scratch to use any templating which makes me balk.

        Have a cookie and a very nice day!
        Lady Aleena

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found