Forum Moderators: coopster

Message Too Old, No Replies

Converting a product database to a web site

To template, or not to template?

         

SeanW

4:21 pm on Feb 20, 2005 (gmt 0)

10+ Year Member



I've got a database of products and categories, and would like to generate a web site out of it dynamically.

I'm currently doing this in Perl and using Template Toolkit, but for many reasons would like to rewrite it in PHP.

URLs would be of the form

[example.com...]

I would likely use mod_rewrite to change that to

/mypage.php?product=productname&catlist=cat1/.../catN

However, I'm unsure about the best way to approach the whole application, since it's been a while since I've done anything large in PHP. Should I use a template class? If so, which ones to look at or avoid?

Thanks,

Sean

hakre

5:35 pm on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



with php there is no need to use a template class. php itself can be used as your "template" system, because it integrates very good into html code (that's a difference to perl, even if there are some solution with perl, i don
't want to ignore here).

in your case mypage.php would be querieyng the data based on category and product and then create the html structure of your page and inserting textual data from your database. that's really simple and with shorttags you can integrate your variables simply in your output:

...html...<?=$variable?>....html....

i think more simple can no template be.

SeanW

8:48 pm on Feb 20, 2005 (gmt 0)

10+ Year Member



The problem as I see it is that I can't reuse elements of my HTML in other pages. If I create "mypage2.php", I have to duplicate a lot of things, and now I have two sets of HTML to maintain. Using a template engine in Perl let me solve that.

That said, I've looked at some template engines in PHP and they don't seem to do it as neatly as TT2 :(

Sean

coopster

8:57 pm on Feb 20, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I reuse html chunks in site design quite often, without templates. It's as simple as placing the HTML in a separate file that you will include() [php.net] or place it in a function.

SeanW

6:58 pm on Feb 21, 2005 (gmt 0)

10+ Year Member



Just to follow up on my own thread, I started using Smarty. On their Wiki I found a way to emulate TemplateToolkit's wrapper functionality, which lets me write sections of php that don't have to care about the site layour (or even know it's part of a site)

It also does caching of both compiled templates and the output, which is something I had to handle myself in the perl engine. Using PHP also lets me do some things like redirects much more cleanly than I was doing before.

Sean

kilonox

9:02 pm on Feb 21, 2005 (gmt 0)

10+ Year Member



I tend to like to rip files (file_get_contents, fread) for html stuff when doing templating just with php. Much faster then using include or a template engine.