drtanz Posted May 14, 2007 Share Posted May 14, 2007 hi i am making a php site and have really become confused about templating. Right now I have the following: A CSS styling file including text formatting and item positions A php 'template' file containing static text and images that should appear on every page Various php files containing php code and html for performing various functions in my cms and displaying the results The php files do very basic formatting so my idea was to have the php template file as the base for all pages, and passing a variable to it depending on the menu selection which will tell the template from which php file to extract the main content. I dont know if this possible however and would like some guidance as to which way i should be doing this. I also read about some templating systems that help in separating design from processing but I dont know if this is what im looking for. Thanks and sorry for my confusion please ask if I need to clarify something. Quote Link to comment https://forums.phpfreaks.com/topic/51392-templating-dilemma/ Share on other sites More sharing options...
btherl Posted May 14, 2007 Share Posted May 14, 2007 You can do that.. one way to do it is like this: $pages = array( 'index', 'news', 'contact', ); switch($_POST['page']) { case 'index': include('index.php'); break; case 'news': include('news.php'); break; case 'contact': include('contact.php'); break; default: include('index.php'); break; } It's always best to list the pages explicitly, so people can't access your files by inventing new pages. Another method is with Smarty (what I use). With that, your templates are stored in seperate files (which are also capable of including each other). If you have a small project, the php method above is fine. For larger projects a system like Smarty helps greatly, as it seperates processing from design, as you said. Quote Link to comment https://forums.phpfreaks.com/topic/51392-templating-dilemma/#findComment-253137 Share on other sites More sharing options...
drtanz Posted May 15, 2007 Author Share Posted May 15, 2007 thanks well explained, and if i switch to smarty could i still include files in the same way or would i then be using objects instead of just passing chunks of code around? thanks Quote Link to comment https://forums.phpfreaks.com/topic/51392-templating-dilemma/#findComment-253458 Share on other sites More sharing options...
drtanz Posted May 15, 2007 Author Share Posted May 15, 2007 I also wanted to ask if the approach you explained for calling pages is better than using dreamweaver's function for making a template with an editable region (to contain the php code) and then applying this template to all pages. Basically this is the reverse approach, instead of including php files into the template, you would be including the template into the php files. thanks Quote Link to comment https://forums.phpfreaks.com/topic/51392-templating-dilemma/#findComment-253464 Share on other sites More sharing options...
drtanz Posted May 15, 2007 Author Share Posted May 15, 2007 any replies? thnx Quote Link to comment https://forums.phpfreaks.com/topic/51392-templating-dilemma/#findComment-253843 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.