homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

I need a new template system.

 11:01 am on Apr 4, 2006 (gmt 0)

Hello... I have a system to make a template using PhP, but it's really not working out... I have used it for over 2 years but I really need to update it...

Right now you call up a page, like index.php, this file then calls temp.php, which holds all the major HTML structure, that file calls on side.php, which holds the side links and navigation... Only problem is that if I have an apostrophe that is not... "crossed out?" then the system will give a parse error...

I need a new system badly... My friend had one where you call up a .txt file or some such nonsense... He says most websites use this template structure.. anyone know of anything better?

I am looking for osmething where I can call up a file easily and quickly without having to worry about apostrophes, plus I give my framework out to other people to use, and I hate having to say "that is the php don't mess with that". I would rather it call a file, and that's it, no more nonsense.

I can give you what I currently have if you would like, it's pretty basic if you ask me... anyone got anything better?

(P.S. I'm really new to php, so... explain slowly)



 11:37 am on Apr 4, 2006 (gmt 0)

You sound like you are in a bit of a mess!

Rather than explain what you have, explain more clearly what you want.

You want to have various pages that uses the same side links (stored in one file), and then content for each page stored in another file, and the structure of the whole page (I guess placing the content and the side links) in a 'main' file.

Is that right?


 1:01 pm on Apr 4, 2006 (gmt 0)

obtemlate may help you there


 2:49 pm on Apr 4, 2006 (gmt 0)

obtemplate? I really don't want a... premade layout, I just need the structure of a good template system...

This is what I want...

I want one page that has most, if not all the HTML coding inside it... I then want a page (maybe 2) of links and navigation, as well as the content you called...

I have seen it in action, any large website uses a template system... or whatever you want to call it. If you update your website you only have to update ONE page, that's the beauty of it... Only problem is how mine is setup...

I want it to use .txt files or something other then echo'ing a page and php include... I want it more stable, so that if I put down "don't" i won't have to have "don\'t" so a parse error doesn't show up... Just a nice and easy system for one page of HTML, pages of content that call that, and the HTML can call up the navigation system (which makes editting easier). Just not under my current system.


 6:08 pm on Apr 4, 2006 (gmt 0)

I have used a couple different approaches but most often I use 2 files, header and footer. Picture a diagonal line through the content section of the page from top left to bottom right. everything above and to the right of this line is in the header. I usually use a container (table/div) to hold the content and the content resides in the actual page and includes the header and footer.

It depends on how different you want your layout to be. Is it a totally different layout or is it just a reskinning? For reskinning (colour changes) I have used a couple things. It depends on the criteria for the colour changes. I sometimes use a control file which loads different colours into variables by section, or whatever the criteria is, then the template uses vars for all colours in it. CSS files can be parsed for php as well and the logic could be done there.

As far as totally different layouts go, you would probably have to include a control file to switch the templates. This could get a little messier and slower but depending on your criteria for the changes you may be able to simplify it. If you wanted different l;ayouts for different sections you could make those sections each in their own directory and put the template for it in the section root and include that.

The key is to make it fast and logical, lots of templating systems are slow and cumbersome.


 7:35 pm on Apr 4, 2006 (gmt 0)

Should I send what I have? lol. What I have is one page, basically the backbone, that is the template page, then some of the text and navigation is held in a side file, then the content in my main portion is held in another file.

So I have content, navigation, and the full backbone... But the way it is coded, is horrible... Having to "escape" an apostrophe gets really annoying fast... Also if I want multiple tables I can approach it so many ways but only know the noob way with alot of coding.

What I am looking for and somewhat found, is a div layout that has a footer, right mid left and a footer. It allows the main content to expand out according to your window space, plus it seems to be structured very nicely..

I added the side tables, mid table and right hand tables but it becomes congested really fast, and breaking it up would be difficult. Too much coding on to many pages. I may have to draw a diagram or something...


 7:44 pm on Apr 4, 2006 (gmt 0)

get a whiteboard, they're my favourite ;)

you shouldn't need to escape quotes in a template, that sounds a little nuts.

have you looked at this thread? it might help a little, might not too.


 8:42 pm on Apr 7, 2006 (gmt 0)

---" by the same token you can also put the header and footer code into a single page called template.php with

include $content;

in the middle. Then you just do this on every page.

$content = "pathtocontentpage.html";
include "template.php"; "---

That was your own post, but i'm confused. That is pretty much waht I have, the entire shell is in my template.php, no biggie, not much of a change. The great change I need is the:

$content = "pathtocontentpage.html";:

but wouldn't that just mean that if I call index.php and it says that, then i'd have to have ANOTHER page called like index_content.php to have it link back to it?

Also if I do have that, couldn't I have it point to like... html_page.txt, would it parse the html coding?


 8:56 pm on Apr 7, 2006 (gmt 0)

You would have something like so:


echo $content;



$content = ' ';

include (template.php);



 12:33 am on Apr 8, 2006 (gmt 0)

AH... AH! But that is EXACTLY what I have. But i'ts flawed! "Flawed?" FLAWED.

I HATE it because someone who doesn't know HTML / Php and has to be taught (i give access to a sub-domain via partnerships), and they don't understand why they have to put:


and not:


Plus they see the top of the page saying title="", and all this stuff and just go "AAHH!" but this whole thing if "content="htmlfile.html" is great, but I dunno if that makes double the files!


 2:18 am on Apr 8, 2006 (gmt 0)

You could also use a heredoc to define the $content variable. Something along the lines of:


$content =<<<EOF

All content goes here. It can be plain text, or it can
contain <html>.

There isn't a need to escape apostrophes.





 8:26 am on Apr 8, 2006 (gmt 0)

obtemplate is not premade system it is just exactly what you want


 9:10 am on Apr 8, 2006 (gmt 0)

I HATE it because someone who doesn't know HTML / Php and has to be taught (i give access to a sub-domain via partnerships), and they don't understand why they have to put:


and not:


I am a little confused. If the people you are giving subdomains to don't know html or php, what exactly are they doing? Are they just writing text files?

If their not using html then why not just use htmlentities() or something similiar to change the quotes?


 3:08 pm on Apr 9, 2006 (gmt 0)

No no, I will teach them the HTML they need, but when your trying to explain paragraphs, breaks, un-ordered lists and so on, then suddenly you throw in, "by the way you can't have an apostrophe" and no one understands that lol. It would be alot easier to not ahve to escape it lol.

So... how does this <<<EOF work anyhow? I know the basic PhP premise I guess, but i've only dipped my finger into the pool of coding.


 3:26 pm on Apr 9, 2006 (gmt 0)

So... how does this <<<EOF work anyhow?




 6:01 am on Apr 12, 2006 (gmt 0)

I love you... LOL


 6:10 am on Apr 12, 2006 (gmt 0)

Why not use something like smarty? (smarty.php.net)
Sure, there is a bit of a learning curve. I use it on all my sites and love it.


 6:52 am on Apr 12, 2006 (gmt 0)

I too would recommend Smarty. It's not too hard to learn, it's easier for non-programmers to learn and it supports built in caching which may or may not interest you (it should :)


 6:27 pm on Apr 12, 2006 (gmt 0)

As much of an amateur I am, I always love the fact that I can say "this is mine" and mean it. Sounds like smarty is something to help, like a program... I'm out to learn hard coding so I can show someone how I made it, and really learn it you know?

I've been doing this for 2-3 years and I learn at my own pace (slow), but when you look at your site you know you made it, and no matter if someone says "your site sucks" you know you can do better then them because they don't program lol.


 9:01 pm on Apr 12, 2006 (gmt 0)

I understand exactly what you're looking for. you want something that has predefined header, footer, navigation and content sections that create what you call a "template." then you want to be able to simply create a new page.html with that structure and simply 'echo', 'include', 'print' whatever the content may be into the structured page.

An easy, simply, no problem included CMS. Yup, that's not too difficult. people will go the .txt file way with that, or you can go the Database way, db way wouldn't be too difficult, you simply create the html file in your server and store the content in a db with the file name, like "home.html" then when you create the html page you see something like:


$page = "home.html";

[query your db for the "home.html" record and its body]

$Data = mysql_fetchrow($blah);
$pagename = $data[0];
$content = $data[1];

echo $content;


BAM, you got what you're looking for, sweet, simple and easy to do...


 1:24 pm on Apr 13, 2006 (gmt 0)

As easy as you explained it, you still lost me lol. My Php experience is very limitted lol, and using a database is beyond me.

Sounds like a nice idea, but your on like... page 100 and I don't even have the book, if you see what i'm saying.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved