Page 1 of 1

Template Based Pages

Posted: Sat Aug 29, 2009 8:03 pm
by tecktalkcm0391
Hello,

I was wondering how I could do a website using one page that is the template, and then loads in content that is created by other scripts. What would be the most effective way of doing this? Would I pretty much just do a "find and replace" and put the content in? What would be the best practice to telling it which content to load?

Thanks for the idea!
Chris

Re: Template Based Pages

Posted: Sun Aug 30, 2009 1:51 am
by cpetercarter
In principle this sounds a good approach. It is sensible to separate business logic from presentation.

If you have not already done so, have a look at the Smarty templating engine. It has features like looping, conditional statements and webpage caching. Perhaps a templating engine sounds like overkill at this stage, but I have found Smarty to be powerful, flexible and easy to use.

Your backend php scripts then just need compute the information you need on your page and send it to Smarty with simple statements like:

Code: Select all

 
$smarty->assign('main_content',$content);