Page 1 of 1

Dynamically change anchor id based on current page.

Posted: Sat Sep 13, 2008 10:28 am
by antoine
I have a pretty basic website started. However, since I know I will have to add/change/delete certain parts of the menu, I decided to make the menu an included PHP file.

However, I also have set up a "current" id for the anchor tag. Normally it would be easy, and I would just add "<a href="somepage.php" id="current">". However, since it is an included page, I was wondering if I could set it up to, depending on which page you are at, add the id="current" dynamically, using PHP of course.

Would I do this on the menu.php file or somewhere on the page where I call the 'include' function?

Thanks. Any help is appreciated,
Antoine

Re: Dynamically change anchor id based on current page.

Posted: Sat Sep 13, 2008 11:46 am
by yacahuma
rememeber that if you include a page , you have access to all the variables declared in the parent page. So you can just assume that a certain variable is defined before including a file

Code: Select all

 
$current_page = 'whatever';
include 'menu.php';
 
then in menu.php you just use the current_page variable

Re: Dynamically change anchor id based on current page.

Posted: Sat Sep 13, 2008 12:10 pm
by antoine
Thanks!

I had tried that earlier and it didn't work, but I just discovered I used " instead of' '.

Thanks for the help!