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

Re: When to use templates?

by freddo411 (Chaplain)
on Nov 19, 2004 at 18:08 UTC ( #409095=note: print w/ replies, xml ) Need Help??


in reply to When to use templates?

When to use templates? When programming a CGI, should you always use templates? When is not a good idea to use templates?
Reasons to use Templates
  • You can edit templates in a GUI
  • You can seperate code (and coders) from the art (and artists)
  • Lots of other reasons, explained in the other messages

Reasons NOT to use Templates
  • Keep everything in one file
  • Don't want to mess with modules
  • Writing very plain vanilla cgi with no decoration
  • Prototyping, so your script is very minimal
    Even then I sometimes use a template that contains only a pre tag.

I use templates 95% of the time. Definitely a "best practice". My template of choice is HTML::Template because is it is so simple.

Cheers

--Fred

-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday


Comment on Re: When to use templates?
Download Code
Re^2: When to use templates?
by revdiablo (Prior) on Nov 19, 2004 at 19:34 UTC
    Keep everything in one file

    There is no reason a template has to be in an external file. With HTML::Template, you can embed your template into the __DATA__ section, and pass DATA as the template filehandle. I do this often, and it works well. I'm sure other template modules have similar methods available.

    I tend to think of a template somewhat like a Perl module. Usually, it's cleaner and better to put these things in separate files. Sometimes, though, embedding them into the file where they're used is far simpler, while still retaining much of the benefit of using modules/templates in the first place.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-09-18 02:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (105 votes), past polls