Template Based Pages

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Template Based Pages

Post 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
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Template Based Pages

Post 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);
 
Post Reply