http://www.perlmonks.org?node_id=946725


in reply to Re: 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. I have yet to find anything that will insert a bunch of code before the main body of the page and another bunch of code at the end of the main body of the page to my specifications. Also, I keep all of my data stored in pipe delineated text files. I've put a sample of what I want to do in my reply to the anonymous monk above.

If you want to see start_html and end_html, let me know; I'll put it on my scratchpad for you to look at.

Have a cookie and a very nice day!
Lady Aleena

Replies are listed 'Best First'.
Re^3: Evaluating subroutines from within data
by Anonymous Monk on Jan 08, 2012 at 00:57 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