Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Separation of content and code

by sierrathedog04 (Hermit)
on Jun 18, 2001 at 13:28 UTC ( #89248=note: print w/replies, xml ) Need Help??


in reply to Re: Separation of content and code
in thread Separation of content and code

OTOH, CGI.pm has a lot of commands for writing tables and other HTML, so a lot of people including me must be mixing their program logic and their HTML in the same file.

What if the structure of the HTML depends upon the program logic? I may for instance show data as a table if more than one row is returned, but as a paragraph otherwise.

I do not believe that it is necessarily better to use templates. Merlyn has an entire chapter on CGI.pm in the 2nd version of Learning Perl, and I don't recall him giving such advice.

Replies are listed 'Best First'.
Re: Re: Re: Separation of content and code
by Masem (Monsignor) on Jun 18, 2001 at 15:26 UTC
    Most template solutions have minimal built in logic to differ output based on program input. (or least I know that Template Toolkit does for sure). However, I only do this when the change is subtle with the overall page keeping much of the same layout; insted it's usually easier to write two different template files if the change is more drastic. Note that still cleans up your perl code, more so than writing two branches of CGI.pm HTML functions.

    But templates are not always the solution in every case. If you have a SSI included script, for example, you only need the minimal HTML that CGI provides. Short, demonstration scripts that aren't really part of a site could easily qualify as well. In addition, if you are building a page that has to be speedy (maybe it's your home page of a million+ hits per day site), a template solution could just slow you down, though if the rest of the site is in template form, it's a tossup. (In general in this situation, your 'entrance' page ought to be statically delievered, which might mean you need to create it every 5 minutes or so from dynamic content).

    But if you are building a site of any magnitue more than a handful of pages, you really ought to be considering templates as to avoid problems with consistent site look after a time.


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2020-07-08 04:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?