Log in

View Full Version : menu in php templates...



pepe_lepew1962
11-10-2013, 10:24 PM
Hello:

I am trying to create templates for my files and I am having a problem with getting the menu to work properly. I have 3 template files, head.php, main.php and foot.php. The head.php contains the following menu html:

<li><a href="www.one.com" class="<?php echo "$head001";?>">One</a></li>
<li><a href="www.two.com" class="<?php echo "$head002";?>">Two</a></li>
<li><a href="www.thr.com" class="<?php echo "$head003";?>">Three</a></li>
<li><a href="www.fou.com" class=<?php echo "$head004";?>>Four</a></li>
<li><a href="www.fiv.com" class="<?php echo "$head005";?>">Five</a></li>

In the main.php, I would like to have 1 variable for what the status of the menu is for that page. For example when the person is on page 3, the class should be current.

$head003 = "Current";

The variable current is in my external css file and changes the appearance. Simple, but for some reason, the variable is not being carrier over. Can you please help.

traq
11-10-2013, 11:49 PM
The variable current is in my external css file ...
Do you mean that you are declaring the variable in your css file (as opposed to in your php file)? CSS does not understand php code.


and changes the appearance.
Meaning it does work? I would assume not, since you're asking for help. Maybe I don't understand your meaning, here.


Simple, but for some reason, the variable is not being carrier over. Can you please help.
"Carried over" from where to where?

= = = = = = = = = =
I think you may be misunderstanding a basic detail of how PHP works. (If you do understand this, please bear with me; many people do not.)

PHP happens first, on your webserver. At this point, there is no such thing as "html" or "css" or "javascript" or "sql." PHP has no idea any of these things exist. Everything that you output via PHP is text, nothing more, nothing less. After it is output (to the browser, database server, etc.), it may be parsed as some other language or markup.

HTML/CSS/JavaScript happens later, on the user's browser. At this point, there is no such thing as "php." The browser has no idea that php ever existed. If you give it PHP code, it will be treated as either plain text or badly formed HTML / CSS / JavaScript.