KansukeKojima 0 Report post Posted March 13, 2008 Description Learn to create easy to edit content-only pages with php. By parsing your layout into your pages, you can reduce file sizes and files will become much neater. Try it out Ok, lets start by creating a file called template.php. <?php//---------------------------------//Layout top section//---------------------------------$top = <<< html<!-- include HTML header code here --><body>INSERT CODE FOR [b]TOP[/b] OF LAYOUT HERE. html;//---------------------------------//Layout bottom section//---------------------------------$bottom = <<< htmlINSERT CODE FOR [b]BOTTOM[/b] OF LAYOUT HERE. </body>html;?> Ok simple enough. We created two variables. $top represents the top part of the layout. This should include all the code that would go over top the content on a regular page. $bottom represents the bottom part of the layout. This should include all the code that would go underneath the content on a regular page. Now for part two! Here is where the "content-only" file comes into play. Create a new file named index.php (or whatever page you want). Make it look similar to the following. <html><?php include ("template.php");echo $top;?>Put your content here!!!<?phpecho $bottom;?></html> Congratualations! You now have "content-only" pages! (I'll be honest.. theres a little php... lol) You can create small, neat, tidy, and easy to edit files! Share this post Link to post Share on other sites
flashy 0 Report post Posted March 14, 2008 Cool this will heelp me for the near future . Thanks a bunchie. Share this post Link to post Share on other sites
galexcd 0 Report post Posted March 15, 2008 (edited) Very good tutorial, but do you mind if I make a slight modification which in my opinion would make the code even better? If you use functions, not only can you write the code in pure html, (not using heredoc), but you can use FUNCTIONS, which are always way cooler looking than no functions For your template file: <? function top(){ ?><!-- include HTML header code here --><html><body>INSERT CODE FOR [b]TOP[/b] OF LAYOUT HERE. <? } function bottom(){ ?>INSERT CODE FOR [b]BOTTOM[/b] OF LAYOUT HERE. </body></html><? } ?> And the actual page: <? include"template.php"; top(); ?>Put your content here!!!<? bottom(); ?> There are a couple reasons I prefer this method. First of all I've never been too much of a fan of heredoc, mainly because my code color coder doesn't color code html in the heredoc (which is super useful, trust me), but there are some other reasons. It just feels messy. An advantage to using functions is that you could pass data to the layout from the content page, such as the title of the page, or perhaps changes in the navigation on certain pages of your website. Now I'm not saying mine is actually better, or more efficient in any way, its just in MY opinion, I like it better, and it would be the way I would do it. I am giving our members another option to choose from. Edited March 15, 2008 by alex7h3pr0gr4m3r (see edit history) Share this post Link to post Share on other sites
KansukeKojima 0 Report post Posted March 15, 2008 Thanks for your input man... I'm not to familiar with functions... unfortuneately..Me and coolcat are using this method for our upcoming gfx site... hmm... I'm definately liking this whole function idea though.. I might have to go in and use that instead of what I was using before... Share this post Link to post Share on other sites
tricky77puzzle 0 Report post Posted March 15, 2008 Thanks for your input man... I'm not to familiar with functions... unfortuneately..Me and coolcat are using this method for our upcoming gfx site... hmm... I'm definately liking this whole function idea though.. I might have to go in and use that instead of what I was using before... Wow, this is exactly what I wanted. Thanks, Kansuke!I wonder if you wrote this as a response to my topic about the includes. Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted March 15, 2008 Functions are good. The best thing about the use of functions is that you only need to 'call' them and they happen. It saves copying a lot of code into the text files, etc. Simply make the function call, and be sure your page can find the function in the "included" file. Typically, you would "include" the function file, which contains all the functions you might use in a page, at the top of each page you build. Share this post Link to post Share on other sites
sonesay 7 Report post Posted March 15, 2008 The way I would do this is have all your entire layout as one file. e.g html > /htmlThen pass $vars to the template for each section, $title, $nav, $content, etc. That way page is always consistent and you only need to update your template to reflect changes across all pages. Another advantage is when it comes to debugging your layout its much easier if its all in one template rather then across different files. If you already are happy with the layout and no longer need to change it it may or may not be easier to update if all sections are broken up into individual files. It may just be personal preference but I find having my whole template in one file makes it easier to update and change since my layouts done in HTML and CSS and its all there. I dont know maybe you guys find it easier if its broken up like header, content, footer files. Think about it if you had to restructure the layout would it be easier to try and do it with 3 different files?I just wanted to add thats how I do mine. its personal preference I guess. Share this post Link to post Share on other sites
alex1985 0 Report post Posted March 25, 2008 A nice tutotrials! Where I can read more about it? Share this post Link to post Share on other sites
KansukeKojima 0 Report post Posted March 25, 2008 Well.. uh.... if you really need more info on it.... you can just ask me stuff via pm and I'll see what I can do... or you can just google for related information. Share this post Link to post Share on other sites
alex1985 0 Report post Posted March 26, 2008 I will do it later on, exams are going on! Share this post Link to post Share on other sites