Best way to implement PHP template

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Lemonz
Forum Newbie
Posts: 1
Joined: Fri Apr 22, 2011 11:01 pm

Best way to implement PHP template

Post by Lemonz »

Hey guys. I want to make a template in PHP but am not sure where to begin. I googled how to create your own template but the results did not satisfy me. They were very basic and was not what I was looking for. I want to make a template where only the content changes but by a navigation bar. Now I know in PHP you can use the $_GET function and based on the variable you are given you display that particular page in the template. However the problem with this is, if you have a lot of pages in your website, your index.php file is going to be huge and only consist a list of "if" and "if else" statements comparing the variable to each type of page you have. I want to avoid this. So is there any other efficient way of creating such a template in php or how can I change the content of the template efficently? Any other help on template creating would be much appreciated.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Best way to implement PHP template

Post by Christopher »

Look into Front Controller and dispatch. Instead of lots of if()s, you generate a file name using the parameter value and load that file as the content.
(#10850)
Post Reply