A very noob mistake...not making templates for my site.
Is there a correct way (or easy way) to make my constant layout into a template?
My navigation at the top of the page stays the same, my stat bar on the left side stays the same, so does my background, but it's what's in my content section that seems to change the most.
Any help would be appreciated.
Templates...[SOLVED]
- RogueTomboy
- Posts: 61
- Joined: Sun May 22, 2011 3:42 pm
Templates...[SOLVED]
Last edited by RogueTomboy on Mon Jul 11, 2011 11:46 am, edited 1 time in total.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Templates...
There are templating packages out there such as Smarty, but I think those are likely way more than you need. What I do for a simple site-wide template is:
1. Create the template for the whole site, or create several templates if the pages need to change significantly.
2. Break them up into sections, such as "Header", "NavBar", "LeftSide", "Footer". You basically break them at each place where custom content will need to go if that makes sense.
3. Put all the parts into their own folder under your root site folder.
4. Then for each unique page you want to make, you would just do it like this:
While this is a simple example, I am sure you can see how it is working out. If you use a code editor that checks for mistakes, don't be surprised when you see errors due to unclosed tags, because sometimes you will have the matching tag in another PHP file for another sections of the page. Just leave them in different parts of the template and it will all be fixed when they are included on the same page.
1. Create the template for the whole site, or create several templates if the pages need to change significantly.
2. Break them up into sections, such as "Header", "NavBar", "LeftSide", "Footer". You basically break them at each place where custom content will need to go if that makes sense.
3. Put all the parts into their own folder under your root site folder.
4. Then for each unique page you want to make, you would just do it like this:
Code: Select all
include_once('pageParts/Header.php');
include_once('pageParts/NavBar.php');
echo "Maybe put some custom content here";
include_once('pageParts/LeftSide.php');
echo "Main custom content for the whole page goes in here, or wherever it works in to the way you broke down your page";
include_once('pageParts/Footer.php');
The indelible lord of tl;dr
- RogueTomboy
- Posts: 61
- Joined: Sun May 22, 2011 3:42 pm
Re: Templates...
Thanks Jack!
That would would for tables right? I have my main layout in tables so I would just basically have to make the same table layout in each page and use an 'include_once blahblahblah.php' for each section of my table that needed the info?
I'll give it a go and thank you muchly for the response!
UPDATE
I fiddled around with it and got my page to work doing this:
So it worked wonderfully - thanks again Jack!
That would would for tables right? I have my main layout in tables so I would just basically have to make the same table layout in each page and use an 'include_once blahblahblah.php' for each section of my table that needed the info?
I'll give it a go and thank you muchly for the response!
UPDATE
I fiddled around with it and got my page to work doing this:
Code: Select all
<?php
include_once('layout/sessionlayout.php');
include_once('layout/header.php');
include_once('layout/content.php');
//what will change on each page
echo "
<table border='0'>
<tr><td width='740'>
<?php
include_once 'blog.php'
?>
</td>
</tr>
</table>";
include_once('layout/mainfoot.php');
?>
Need art? Commissions are always open!
http://www.ladytankstudios.com
Currently addicted to:
Collect & Explore for pets
http://www.ladytankstudios.com
Currently addicted to:
Collect & Explore for pets
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Templates...
Glad you got it worked out!
However, you should look into working further with CSS and dropping tables for layout. There is so much more you can do with CSS, especially with CSS3 on the horizon (can you say rounded corners, tilted content, etc.? )
However, you should look into working further with CSS and dropping tables for layout. There is so much more you can do with CSS, especially with CSS3 on the horizon (can you say rounded corners, tilted content, etc.? )
The indelible lord of tl;dr
Re: Templates...
Yeah I used to use all tables, and then I was like, eh, I'll give a little CSS a try, and now practically every visible piece of content is created with CSS! I love it!
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny