Figured I would throw myself into this
I am making a script now that looks to grow into a CMS type thing.
This has caused me to struggle with ways to create a
Template Type of Thing.......
Since I have used many stuff in the past that have template engines, at first that idea
was in my mind for my code, but as I thought about it more and more, I decided to stray
away from that route, at least for now.
Template engines are very nice, but then you have to start making your code around
the template engine, and lose the original aspect.
They also cause many limitations, at least have for me in the past.
The way I decided to go about having a template'able code, is simple.
It still requires some direct code formatting from sql queries, but I plan to fix that later.
Basically, I create a var that will allow to easily change a template set.
Then in all the main files, calls for something like the below
Code: Select all
include("./templates/$template/header.php");
include("./templates/$template/headermenu.php");
include("./templates/$template/body.php");
include("./templates/$template/left.php");
include("./templates/$template/footer.php");
Then as you guessed it, the actual content of the site would be store in the
proper ./template folder and file.
Each template file is a php file, so that php can still be used.
The template design is also all css, and the css file to be used is defined in the
templates/yourtemplate/header.php
So once that is set up---- which does take a long time to do if you have a big site already,
it is extremly easy to fully change the whole design of the site just by changing the var
And you dont have to worry about tags or other stuff.
For some people this may not work because they would rather write around a template engine
and just include tags in their files.
But for me, this has the most desirable effect and allows me to have
as many templates as I want and change them just as easy
To see more of how I am doing it below are direct examples.
index.php
Code: Select all
include("./templates/$template/header.php");
include("./templates/$template/headermenu.php");
include("./templates/$template/body.php");
include("./templates/$template/left.php");
include("./templates/$template/footer.php");
templates/blahblah/header.php
Code: Select all
echo "
<html>
<head>
<link href='style.css' type='text/css' rel='stylesheet'/>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<title> $sitename </title>
</head>
$indextext
<div id='submiddle'></div>
";
templates/blahblah/body.php
Code: Select all
echo "<div id='mainbody'><h1 class='fivenewbash'>Bash My Ex d0t c0m<br />Newest Bashes</h1>";
echo $newsfunctions->show_last_five_entries();
echo "</div>";
The above returns my site's index with the header/main content showing
As you can see, I am sorta using a template engine 'tag' type of thing, except
my tags are actually variable being defined in other files
