Page 1 of 1
template selector
Posted: Mon Jul 12, 2010 7:06 pm
by nite4000
hey All
I have a task i am trying to complete.
I want to have like 3 layouts each in a folder called layout1,layout2,and layout3 now in the db i want to have a tabled called layout and a field called template and in the field i want to have like layout2/index.html
now when I would go to like
http://www.mydomain.com it will chk and load the template that is in that field. I dont have a drop box or anything so I will have to change it manual til i make one but this was the major part of my task
Any help would be nice.
Re: template selector
Posted: Tue Jul 13, 2010 9:30 am
by Jade
Do you have a database setup all ready? Have you tried to code any of this on your own yet? The basic idea is that whenever your website loads a page it will need to check which template it's using, and then implement that template. I would suggest writing everything in CSS and then just loading different stylesheets as this is the easiest way and gives you the most flexibility, for example
CSS Zen Garden can show you the awesome power of CSS.
Re: template selector
Posted: Tue Jul 13, 2010 9:53 am
by nite4000
yeah i have a db setup and i know i would have to have the site chk for the template its using just not sure how to begin. i know i have to define the template to use in teh db then use the site to load that template from the correct folder.
Re: template selector
Posted: Tue Jul 13, 2010 10:25 am
by AbraCadaver
nite4000 wrote:hey All
I have a task i am trying to complete.
I want to have
like 3 layouts each in a folder called layout1,layout2,and layout3 now in the db i want to have a tabled called layout and a field called template and in the field i want to have
like layout2/index.html
now when I would go to
like http://www.mydomain.com it will chk and load the template that is in that field. I dont have a drop box or anything so I will have to change it manual til i make one but this was the major part of my task
Any help would be nice.
Are you a teenage girl?

Re: template selector
Posted: Tue Jul 13, 2010 11:03 am
by nite4000
how about you dont reply if you are going to be a smartass
Re: template selector
Posted: Tue Jul 13, 2010 12:02 pm
by Jade
Okay so basically you're going to create a file called template_config.php:
Code: Select all
session_start(); //we use sessions so we don't query all the time
include('dbconnect.php'); //this is an include file with the connection to your database
if (!$_SESSION['template']) //there is no template loaded
{
//select all the information from your table for whatever template you have marked as active.
//if you don't have an active field (bool) then I would add one, this way you can just change whatever the active template is
//and your site will reflect that change as soon as the template is re-loaded into the session
$result = mysql_query("SELECT * FROM database_name_here WHERE active='1'")
or die (mysql_error());
$row = mysql_fetch_array($result);
$_SESSION['template'] = $row['template_file_name']; //or whatever the field is with the CSS file name in it
}
?>
And on any page you want to use the templates, just include your template page and echo the session's template information:
Code: Select all
<?php
include('template_config.php');
?>
<html>
<head>
<title>My Website</title>
<link rel="stylesheet" type="text/css" href="<?php echo $_SESSION['template']; ?>" />
</head>
<body>
This is where the rest of your page goes
</body>
</html>
Re: template selector
Posted: Tue Jul 13, 2010 12:07 pm
by AbraCadaver
nite4000 wrote:how about you dont reply if you are going to be a smartass
Just good natured fun, hence the

And you didn't answer the question.
