Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: html template in a perl script

by cees (Curate)
on Sep 21, 2003 at 02:06 UTC ( #292947=note: print w/ replies, xml ) Need Help??


in reply to html template in a perl script

Sounds like a reasonable way to organize things to me, as long as your CGI scripts are quite simple. I wouldn't use that model myself, because I use lots of includes in my templates to provide a consistent look and feel to the application. But if your scripts only needs one template, then the DATA method seems like a good option...

It will also be slightly quicker than an external template, since perl will only need to access one file, instead of opening two.


Comment on Re: html template in a perl script
Re: Re: html template in a perl script
by bradcathey (Prior) on Sep 21, 2003 at 13:18 UTC
    cees , can you provide anymore info on the DATA method? I use HTML::Template, but sometimes it's overkill. It sounds like this might be simpler/faster/easier.

    Thanks.
      Um, the DATA method is what we are talking about! You just put your template in the DATA section of your Perl script. I use this all the time for simple CGI scripts and examples i post here at the Monastery - but for anything serious, i use another file for the template. As for your overkill problem, the more you use HTML::Template the less the overkill seems to be a problem.

      As for your problem at Re: html template in a perl script, have you looked into Template yet? Kake Pugh has an excellent article over at perl.com: How to Avoid Writing Code that demonstrates how well that Class::DBI works with Template Toolkit.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

      If you read the original question again, you will see what the DATA method that I am talking about refers to. It is a method for adding a __DATA__ section to your perl code, where perl will automatically provide this data in the file handle DATA. The above question gives an example of how to use this using HTML::Template.

      For more info, check out perldoc SelfLoader for some more info on __DATA__.

      - Cees

Re: Re: html template in a perl script
by archen (Pilgrim) on Sep 24, 2003 at 16:26 UTC
    Template includes in a template is something I hadn't thought to consider. I usually don't include other templates, but I can see how it could become an orginizational nightmare having some HTML in the scripts, and some in templates laying around elsewhere. Good call, I'll keep this in mind!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2014-12-27 02:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls