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.
template selector
Moderator: General Moderators
Re: template selector
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
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.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: template selector
Are you a teenage girl?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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: template selector
how about you dont reply if you are going to be a smartass
Re: template selector
Okay so basically you're going to create a file called template_config.php:
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
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
}
?>
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>
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: template selector
Just good natured fun, hence thenite4000 wrote:how about you dont reply if you are going to be a smartass
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.