Templates...[SOLVED]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
RogueTomboy
Posts: 61
Joined: Sun May 22, 2011 3:42 pm

Templates...[SOLVED]

Post by RogueTomboy »

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.
Last edited by RogueTomboy on Mon Jul 11, 2011 11:46 am, edited 1 time in total.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Templates...

Post by Jackolantern »

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:

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');
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.
The indelible lord of tl;dr
User avatar
RogueTomboy
Posts: 61
Joined: Sun May 22, 2011 3:42 pm

Re: Templates...

Post by RogueTomboy »

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:

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');
?>
So it worked wonderfully - thanks again Jack!
Need art? Commissions are always open!
http://www.ladytankstudios.com

Currently addicted to:
Image
Collect & Explore for pets
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Templates...

Post by Jackolantern »

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.? :D )
The indelible lord of tl;dr
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Re: Templates...

Post by 62896dude »

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
Post Reply

Return to “Beginner Help and Support”