Copy link to clipboard
Copied
Let's say I created a header.php file in my includes folder. And I include it in my index.php file in the site root directory.
Then in the header.php file, I have a link to the style sheet.
The issue I've always found is that you can't get the header.php file to apply the stylesheet.
I can get it to work using global links, however I don't want to do that as I'll have to undo them before I upload the site. (And I forget....)
So anyways, I came up with this code today in an attempt to overcome this. Here is my header file so far:
<!-- SETTING MY VARIABLES -->
<?php
$directory = getcwd()
?>
<?php
$currentFolder = strpos($directory, "includes");
?>
<!--END OF VARIABLES -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<!-- SCRIPT TO PROCESS STYLE SHEET -->
<?php
if($currentFolder !== false) {
echo "<link href=\"../styles/stylesheet.css\" rel=\"stylesheet\" type=\"text/css\" />";
} else
echo "<link href=\"styles/stylesheet.css\" rel=\"stylesheet\" type=\"text/css\" />";
?>
<!-- END OF SCRIPT FOR SYTLE SHEET -->
</head>
<body>
<div id="headerWrapper"></div>
So here is what it is doing:
1. It is creating a variable called $directory which is equal to the current directory.
2. Then it is creating another variable called $currentFolder which is equal to whether or not the variable $directory contains the word "includes".
3. Then it says if $currentFolder is NOT false then it has the location of the stylesheet in relation to the header.php file.
4. Else - if it IS false then the stylesheet is located in a location in relation to files in my root directory.
This works perfectly fine....in Live view. Both the header.php and index.php will format the header in live view. Neither though will format it in Design view. Which sucks cause I was pretty happy that I came up with this code on my own.
The reason it isn't working in Design View - I realize now - is because Dreamweaver won't process that script in Design View.
Does anyone know of a way to get this script to run in Design View? Or maybe some suggestions on editing this code to get it to work in Design View?
Thanks!
>The issue I've always found is that you can't get the header.php file to apply the stylesheet.
Right. That's because, and it seems you understand this already, the css file relative location is different from the point of view of the header file, and the parent file. Since the header file is included in the parent at the server, the client then sees the css file in the wrong location.
The solution is to use Design time style sheets. This will apply the css to the page only in design time - it won
...Copy link to clipboard
Copied
I don't know if anyone will have a solution or suggestion. In the event that nobody will reply; I've decided it isn't that important. I'll just attach the style sheet to both files. I just did this and the index.php passed W3C validation and it isn't printing out any errors. So it must not be a big deal doing it this way.
Copy link to clipboard
Copied
>The issue I've always found is that you can't get the header.php file to apply the stylesheet.
Right. That's because, and it seems you understand this already, the css file relative location is different from the point of view of the header file, and the parent file. Since the header file is included in the parent at the server, the client then sees the css file in the wrong location.
The solution is to use Design time style sheets. This will apply the css to the page only in design time - it won't actually insert the css file into the code. So, insert the css reference into the header file from the point of view of the parent - index.html. Then add a design time style sheet. That should work.
Copy link to clipboard
Copied
Design time style sheet? I'm not familiar with this. Can you elaborate? Thanks!
Copy link to clipboard
Copied
Design-Time Style Sheets
http://help.adobe.com/en_US/dreamweaver/cs/using/WScbb6b82af5544594822510a94ae8d65-7e17a.html
Nancy O.