Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

How to design website structure?

by kitsune (Acolyte)
on Feb 13, 2010 at 05:41 UTC ( #822977=perlquestion: print w/replies, xml ) Need Help??
kitsune has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to use Perl to design the foundation of my website. It has multiple pages. Each page looks the same, except for the content section. Thus, I have a template page and what I do currently is use PHP's include() function to include the header and footer onto each page.

What I want to do now is use mod_rewrite to redirect to and then process that variable "page" using CGI and HTML::Template (and other modules if necessary). Is there a way to set my .tmpl file to include a file based on what the variable "page" holds? Should these included files by html files or pl files? Also, some of the content files might require Perl in them. How would I get this done?

Thank you!

Replies are listed 'Best First'.
Re: How to design website structure?
by CountZero (Bishop) on Feb 13, 2010 at 12:28 UTC
    Do not re-invent the wheel: go and have a look at Catalyst which is just the framework you will need.


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: How to design website structure?
by Your Mother (Chancellor) on Feb 13, 2010 at 17:30 UTC

    Mason and Template will be more "familiar" than HTML::Template as they allow you to embed code, macros, and mini-language directives. In TT2 (Template) you could have a structure like so-

    [% PROCESS %] [% PROCESS ${variable_template_name_from_code}.tt %] [% PROCESS %]

    -and then pass the middle template name in your code. There are many ways to do this sort of thing and you'll need to read the docs carefully but you can already see how easy it is to organize templates into reusable parts.

      Another option with TT is to use the WRAPPER setting.
      my $tt = Template->new(WRAPPER => '', ...); $tt->process('', ...);
      You then put your header/footer code into and, wherever you want the body content to appear, insert [% content %]. If the header/footer are in separate files, as in YourMother's example, would be:
      [% PROCESS %] [% content %] [% PROCESS %]
Re: How to design website structure?
by pajout (Curate) on Feb 13, 2010 at 13:01 UTC
    Kitsune, there are many ways how to do it. For instance, if pages are completely static, I do not use Perl but I design some layout.xml and page1.xml, ..., pagelast.xml and build final html pages using XSLT machine, then I publish that static html pages. Or, if pages are dynamic, you can use mod_perl handler or CGI to launch your Perl code when somebody requests your page. Once your code is launched, you can compute dynamic values and use some template system for htmlization. HTML::Template is good choice, Petal is another.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://822977]
Approved by Old_Gray_Bear
[marto]: Anyone care to check Nodes to consider, and help me correct a brainfart? Thanks
[marto]: My edit should have stated 'retitle'

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-07-23 12:49 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (347 votes). Check out past polls.