Solved

Changing templates using php.

Posted on 2006-11-22
6
270 Views
Last Modified: 2008-03-03
Hi,

I've made 3 templates or more exactly 3 folders that have different pictures and css files in them.
And the index.php looks the following way:


<?php
$folder=$_REQUEST["folder"];
?>

<head>

<title>Toubes Design</title>
 <meta content="Web Design, Internetsivut, Kotisisvut" name="Toubes Design" />
 <link rel="stylesheet" href="<?=$folder?>/toubesdesign.css" />
</head>
<body>

<div id="banner">
<img src="<?=$folder?>/banner_test1.jpg"/>
</div>
<p class="nav">
<a href="http://www.toubes-page.net/td"><img src="<?=$folder?>/etusivu_o.jpg" name="etusivu" width="91" height="25" border="0"></a></p>

<p class="nav">
<a href="yritys" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('yritys','','<?=$folder?>/yritys_o.jpg',1)"><img src="<?=$folder?>/yritys.jpg" name="yritys" width="72" height="25" border="0"></a></p>


<p class="nav">
<a href="palvelut" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('palvelut','','<?=$folder?>/palvelut_o.jpg',1)"><img src="<?=$folder?>/palvelut.jpg" name="palvelut" width="95" height="25" border="0"></a></p>

<p class="nav">
<a href="portfolio" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('portfolio','','<?=$folder?>/portfolio_o.jpg',1)"><img src="<?=$folder?>/portfolio.jpg" name="portfolio" width="100" height="25" border="0"></a></p>

<p class="nav">
<a href="yhteystiedot" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('yhteystiedot','','<?=$folder?>/yhteystiedot_o.jpg',1)"><img src="<?=$folder?>/yhteystiedot.jpg" name="yhteystiedot" width="120" height="25" border="0"></a></p>

<p class="nav"><img style="border: none; width: 422px; height: 25px;" src="<?=$folder?>/right.jpg" alt="left" /></p>
<br/><br/>

</div>

<div id="bg">
<div class="logo_bg">
<div></div>


<p class="navtop"></p>
<div class="left_box">
<div id="left_bar">
<span style="margin-left: 33px; font-size: 11px;">Ajankohtaista</span>
</div>
<div id="left_sisalto"><span style="color: #ffffff; font-weight: bold;">16.11.2006</span> - Toubes Design sivut saanut uuden ulkoasun, palautetta saa antaa.<p id="hr"></p>

<span style="color: #ffffff; font-weight: bold;">10.9.2006</span> - Mets&auml;m&auml;ki Tuotanto Oy:n sivut saatiin valmiiksi. <p id="hr"></p>
Lis&auml;&auml; uutisia <span class="linkit"><a style="font-size: 11px;" href="index.php?id=content&page=uutisia">t&auml;&auml;ll&auml;.</a></span>
</div>

</div>

<div class="middle_box">

<div id="middle_bar">

<?php

if (isset($_GET['page']) && isset($_GET['id']) && file_exists('pages/'.$_GET[id].'/'.$_GET[page].'.php'))
{
       include 'pages/'.$_GET[id].'/'.$_GET[page].'.php';
}
else
{
      include 'pages/content/main.php';
}
?>

</div>
</div>

</div>

<div class="left_box_low">
<div id="left_bar">
<span style="margin-left: 33px; font-size: 11px;">2 Uusinta</span>
</div>
<div id="left_sisalto">
Kaksi viimeisimm&auml;t websivujen tuotannot ovat:
<ul class="linkit">
<li style="list-style-image: url(<?=$folder?>/point.jpg);"><a style="font-size: 11px;" href="http://www.metsamaki.fi" onclick="window.open('http://www.metsamaki.fi'); return false;">Mets&auml;m&auml;ki Tuotanto Oy</a></li>
<div style="padding-top: 6px;"></div>
<li style="list-style-image: url(<?=$folder?>/point.jpg);"><a style="font-size: 11px;" href="http://www.sipoo.fi/kallback_barntradgard/" onclick="window.open('http://www.sipoo.fi/kallback_barntradgard/'); return false;">Kallb&auml;ck Barntr&auml;dgård</a></li>
</ul>

</div>

</div>

<div class="left_box_low">
<div id="left_bar">
<span style="margin-left: 33px; font-size: 11px;">Ota yhteytt&auml;</span>
</div>
<div id="left_sisalto">
Jos haluat ottaa meihin yhteytt&auml;, antaa palautetta tai j&auml;tt&auml;&auml; tarjouspyynt&ouml; voit tehd&auml; sen yhteystiedot sivulta. <a href="index.php?folder=kesa">kesä</a> <a href="index.php?folder=talvi">Talvi</a> <a href="index.php?folder=syksy">Syksy</a>
<ul class="linkit">
<li style="list-style-image: url(<?=$folder?>/point.jpg);"><a href="http://www.toubes-page.net/td/yhteystiedot">Yhteystiedot sivulle</a></li></div>
</ul>
</div>

</div>

<div id="footer">
<div id="footer_text">Nallitie 8 D 24 | 00940 Helsinki | 050-4342840 | info@toubesdesign.com </div>
<img id="footer2" src="<?=$folder?>/footer2.jpg"/>

</body>
</html>

i got some good advices from the following page:
http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_22066053.html 

So what I have done is that I have replaced all the images url with <?=$folder?> and changing the the templates with the following link: index.php?folder=kesa

But the problem that I'm having is that when a user browses to the main address of the page in this case http://www.toubes-page.net/td/test/ the css file is not activated and the whole page looks very messy.

So is there some way to get the main address to work?

Thanks in advance.

-Toby
0
Comment
Question by:Toube
  • 3
  • 3
6 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 17994652
You should make sure that $folder has a default value. Such that when no specific template is chosen $folder always points to your default template directory.

-r-
0
 

Author Comment

by:Toube
ID: 17994667
Hi,

f ($_REQUEST["folder"] <> ""){
  <link rel="stylesheet" href="<?=$_REQUEST["folder"]?>/style.css />
}else{
 <link rel="stylesheet" href="syksy/style.css />
}

got this to test out.. but I can't get it to work, and I'm not sure where to place the could?

Thanks,

Toby
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 17994708
You'd rather have:

$templates = array('syksy', 'template2','template3');

if(isset($_REQUEST['folder']) && in_array($_REQUEST['folder']) {
  $folder = $_REQUEST['folder'];
} else {
  $folder = 'syksy';
}


And then just use <link rel="stylesheet" href="<?php echo $folder;?>/style.css" />

-r-
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:Toube
ID: 17994740
ok, got the default working now, but when I try to change the style it gives me the follownig error:


Warning: Wrong parameter count for in_array() in /home/pt4517/public_html/td/test/index.php on line 6

Line 6: if(isset($_REQUEST['folder']) && in_array($_REQUEST['folder']))

-Toby
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 400 total points
ID: 17994781
yeah, my err.

Should be:  in_array($_REQUEST['folder'], $templates)

-r-
0
 

Author Comment

by:Toube
ID: 17994899
Thanks, it works.

Though now I have one more little thing, how do i get the template to stay selected when i change pages in the site.. so that it doesn't reverse back to the default template when a link is clicked?

when I go to the page http://www.toubes-page.net/td/test/index.php?id=content&page=uutisia and i have selected another template than the default one, but it still changes the template to default?

Thanks,

-Toby
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHPStorm debugging issues 1 45
Attach to file (img) a unique id 8 26
mysql date time 14 30
Is there an elegant way to view sql statements written in PDO? 2 6
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question