Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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 mydomain.com/path/to/file to mydomain.com/index.pl?page=path/to/file 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!

Comment on How to design website structure?
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.

    CountZero

    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 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.
Re: How to design website structure?
by Your Mother (Canon) 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 header.tt %] [% PROCESS ${variable_template_name_from_code}.tt %] [% PROCESS footer.tt %]

    -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 => 'wrapper.tt', ...); $tt->process('whatever.tt', ...);
      You then put your header/footer code into wrapper.tt and, wherever you want the body content to appear, insert [% content %]. If the header/footer are in separate files, as in YourMother's example, wrapper.tt would be:
      [% PROCESS header.tt %] [% content %] [% PROCESS footer.tt %]

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (15)
As of 2014-09-18 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (120 votes), past polls