daveoffy Posted January 3, 2009 Share Posted January 3, 2009 I have been making a HTML and CSS template and just reuse that page and add different PHP files to it and whatever, but when it comes down to changing the look it takes forever since I have to edit every page. How will I go about making a single template page and than just have the other pages just PHP. I searched google but it didn't work out that great since I don't know what to search for. Quote Link to comment https://forums.phpfreaks.com/topic/139332-solved-php-template/ Share on other sites More sharing options...
premiso Posted January 3, 2009 Share Posted January 3, 2009 Smarty Template System is probably the best/most robust out there. That is my suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/139332-solved-php-template/#findComment-728746 Share on other sites More sharing options...
daveoffy Posted January 3, 2009 Author Share Posted January 3, 2009 Is there any other ways? Quote Link to comment https://forums.phpfreaks.com/topic/139332-solved-php-template/#findComment-728869 Share on other sites More sharing options...
T-Bird Posted January 3, 2009 Share Posted January 3, 2009 A friend and I had built a template system for one of our sites not long ago. It's actually not all that difficult. None of the pages you navigate to (I.E. domain.com/help.php) should have any HTML in them. Instead all HTML and CSS should be set in external files broken into modular blocks. So you might have header.htm, navbar.htm, body.htm, footer.htm. Your main files like help.php will simply use the include() function to attach the html files where necessary. Since things like your header wont be changing between pages on the site this lets you edit one HTML file and make a global change to your site. Quote Link to comment https://forums.phpfreaks.com/topic/139332-solved-php-template/#findComment-728886 Share on other sites More sharing options...
DarkSuperHero Posted January 3, 2009 Share Posted January 3, 2009 for those of you who know how to use smarty template system, how long did it take to pick up on it right ? :-) Quote Link to comment https://forums.phpfreaks.com/topic/139332-solved-php-template/#findComment-728907 Share on other sites More sharing options...
daveoffy Posted January 3, 2009 Author Share Posted January 3, 2009 A friend and I had built a template system for one of our sites not long ago. It's actually not all that difficult. None of the pages you navigate to (I.E. domain.com/help.php) should have any HTML in them. Instead all HTML and CSS should be set in external files broken into modular blocks. So you might have header.htm, navbar.htm, body.htm, footer.htm. Your main files like help.php will simply use the include() function to attach the html files where necessary. Since things like your header wont be changing between pages on the site this lets you edit one HTML file and make a global change to your site. Could you talk to me on aim or something and tell me a little more about it. My aim is daveoffy or you could just reply to this topic. Quote Link to comment https://forums.phpfreaks.com/topic/139332-solved-php-template/#findComment-728912 Share on other sites More sharing options...
T-Bird Posted January 4, 2009 Share Posted January 4, 2009 Basically we built the HTML page for starters. We then "chunked" it out, or modularized it. Each "chunk" went into it's own .htm file in a subdirectory named "templates". So this file: <html> <head> <title>Document</title> </head> <body> <div>This is a header</div> <div>This is a nav bar</div> <div>This is the body</div> <div>This is the footer</div> </body> </html> Would be broken into four seperate files, (in this case one for each of those div tags and their content). The PHP file would then look like: <?php /*Code executed before the html-headers are sent goes here*/ ?> <html> <head> <title>PHP TEMPLATE EXAMPLE</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php /*Code executed before the page head is created goes here*/ include('/templates/header.htm'); /*Code executed before the page navigation bar is created goes here*/ include('/templates/navbar.htm'); /*Code executed before the page body is created goes here*/ include('/templates/body.htm'); /*Code executed before the page footer is created goes here*/ include('/templates/footer.htm'); ?> </body> </html> Now when you want to change the page design you simply change header.htm, navbar.htm, body.htm, and footer.htm as needed. Of course your site will probably be broken down differently, this was a basic example, but you get the point. Quote Link to comment https://forums.phpfreaks.com/topic/139332-solved-php-template/#findComment-729217 Share on other sites More sharing options...
jonsjava Posted January 4, 2009 Share Posted January 4, 2009 Basically we built the HTML page for starters. We then "chunked" it out, or modularized it. Each "chunk" went into it's own .htm file in a subdirectory named "templates". So this file: <html> <head> <title>Document</title> </head> <body> <div>This is a header</div> <div>This is a nav bar</div> <div>This is the body</div> <div>This is the footer</div> </body> </html> Would be broken into four seperate files, (in this case one for each of those div tags and their content). The PHP file would then look like: <?php /*Code executed before the html-headers are sent goes here*/ ?> <html> <head> <title>PHP TEMPLATE EXAMPLE</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php /*Code executed before the page head is created goes here*/ include('/templates/header.htm'); /*Code executed before the page navigation bar is created goes here*/ include('/templates/navbar.htm'); /*Code executed before the page body is created goes here*/ include('/templates/body.htm'); /*Code executed before the page footer is created goes here*/ include('/templates/footer.htm'); ?> </body> </html> Now when you want to change the page design you simply change header.htm, navbar.htm, body.htm, and footer.htm as needed. Of course your site will probably be broken down differently, this was a basic example, but you get the point. lol. I thought I was so smart when I figured out that trick. it's the fastest way to template. I agree with T-bird's method. Quote Link to comment https://forums.phpfreaks.com/topic/139332-solved-php-template/#findComment-729247 Share on other sites More sharing options...
daveoffy Posted January 5, 2009 Author Share Posted January 5, 2009 Ya, I was just sitting down at my desk lastnight and was thinking and thought of it. It works out great! Quote Link to comment https://forums.phpfreaks.com/topic/139332-solved-php-template/#findComment-729643 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.