[Solved] Changing CSS using an IF statement in a Menu

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Locked
Frankie

[Solved] Changing CSS using an IF statement in a Menu

Post by Frankie »

I am using this bit of code to change the CSS and highlight that menu item if it is the currently loaded page:

Code: Select all

{if $page == "home"}<li><a href="/" class="on">Home</a></li>{else}<li><a href="/">Home</a></li>{/if}
My question is, how can I get the HOME menu item to be affected by the IF statement when "index.php?page=home" is not being used and it's just at the root ".com/'?

Thank you for the help, you coders are so much more talented than this wannabe dev designer  ;D
Last edited by Frankie on Tue Jan 27, 2009 12:09 am, edited 1 time in total.
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: Changing CSS using an IF statement in a Menu

Post by Dee »

I'm not sure if I understand the question completely.
If the page with alias 'home' is set as the default page, the menu item will be affected by the IF statement when you are on the homepage, whether it's called as index.php?page=home, domain.com/index.php or just domain.com/

Regards,
D
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: Changing CSS using an IF statement in a Menu

Post by Nullig »

The standard menu templates already highlight the active menu item.

Nullig
Frankie

Re: Changing CSS using an IF statement in a Menu

Post by Frankie »

Solved. I used the page ID instead of the alias.

The main issue was that when I would use the root "/" as the URL on navigation CMSMS wasn't recognizing the alias "home" as being loaded (since index.php?page=home wasn't being used)...changing my value to the page ID solved this problem. Thanks for responding!

Below was the easy solution to this problem!

Code: Select all

{if $page == "15"}<li><a href="/" class="on">Home</a></li>{else}<li><a href="/">Home</a></li>{/if}
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: [Solved] Changing CSS using an IF statement in a Menu

Post by Dr.CSS »

If you would have looked thru the default install pages you would have seen that every menu template that comes with it has a currentpage type in them so you can target the current page to be styled your way, you don't have to do all that you do now to get what you need...
Locked

Return to “Layout and Design (CSS & HTML)”