nexushosting Posted March 31, 2011 Share Posted March 31, 2011 Hey Guys, I'm trying to apply a class to a link based on the page for the site navigation. I tried what I would usually do in this instance, but it just appears as text on the page. Is there any way I can achieve this? Here's what I have: Head: <?php $page = basename($_SERVER['SCRIPT_NAME']); ?> then the link; <li><a <?php if ($page == 'clientarea.php?action=invoices') { ?>class="current"<?php } ?> href="clientarea.php?action=invoices">Invoices</a> </li> What I am trying to get as the end result: the page is clientarea.php?action=invoices, then the link is <li><a class="current" href="clientarea.php?action=invoices">Invoices</a> </li> Thanks! Matt http://www.hostnexus.com.au 0 Quote Link to comment Share on other sites More sharing options...
bear Posted March 31, 2011 Share Posted March 31, 2011 http://wiki.whmcs.com/Template_Syntax In Smarty parsed pages, "<?php" is text and nothing special. You need to use {php}{/php} to enclose php snippets, usually. 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted March 31, 2011 Share Posted March 31, 2011 You don't need the head part as $page is a smarty var already Use like this <li><a {if $page == 'clientarea' && $smarty.server.get.action =='invoices')class="current"{/if} href="clientarea.php?action=invoices">Invoices</a></li> 0 Quote Link to comment Share on other sites More sharing options...
nexushosting Posted March 31, 2011 Author Share Posted March 31, 2011 Thanks sparky, I have tried this but when I open the page for some reason it killed all the css? I have also tried what bear suggested and it just killed the whole page. Any other suggestions would be greatly appreciated. Thanks! Matt http://www.hostnexus.com.au 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted March 31, 2011 Share Posted March 31, 2011 There was an error there sorry a ) instead of a } <li><a {if $page == 'clientarea' && $smarty.server.get.action =='invoices'}class="current"{/if} href="clientarea.php?action=invoices">Invoices</a></li> 0 Quote Link to comment Share on other sites More sharing options...
nexushosting Posted March 31, 2011 Author Share Posted March 31, 2011 There was an error there sorry a ) instead of a } Thanks sparky, the css is working again, but the class still does not apply. I have tested on multiple pages. Any other ideas? Thanks, Matt http://www.hostnexus.com.au 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted March 31, 2011 Share Posted March 31, 2011 Is the class="current" showing in the link or a tag? Maybe you are not referencing the link correctly. Should you not be applying the class to the li item? 0 Quote Link to comment Share on other sites More sharing options...
nexushosting Posted April 1, 2011 Author Share Posted April 1, 2011 Hi sparky, I am applying the class to a <li> item, and when I view the source of the document, it does not appear at all: <li> <a (where it should be) href="#">Billing</a> <ul> <li><a href="clientarea.php?action=invoices">Invoices</a> </li> Any ideas? I know I am applying the right class in the right place, as it works if I just make it static. Matt http://www.hostnexus.com.au 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted April 1, 2011 Share Posted April 1, 2011 Is this the one you mean? #topnav ul li .current { color:#39c; background:transparent url(../../images/skin7/topnavBG.png) -100px -76px no-repeat; } If so then you are not referencing the the <a> tag at all. If not then please supply a url to the nav menu in question or post the css involved and the html for the area you need the help on. Give some detailed info and you should be able to get the answer that you are after! 0 Quote Link to comment Share on other sites More sharing options...
nexushosting Posted April 1, 2011 Author Share Posted April 1, 2011 Hi sparky, Thanks very much for your help, I have created a testing account for you: e: test@hostnexus.com.au p: sparky url: https://manage.hostnexus.com.au/clientarea.php You will see the navigation menu up the top of the page, in a 'tab' style. You will see that I am wanting to get the 'Client Area', 'Billing', 'Services', and 'Support' tabs to be the current class when the pages below them are selected. Thanks once again, Matt http://www.hostnexus.com.au 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted April 1, 2011 Share Posted April 1, 2011 You do realise that this is a public forum!! You would have been wiser to PM the login details. You may want to ask Bear to remove that from your post 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted April 1, 2011 Share Posted April 1, 2011 Your css is working fine... it's your scripting When you click on billing and then invoices the current class name is assigned to clientarea instead of billing. 0 Quote Link to comment Share on other sites More sharing options...
nexushosting Posted April 1, 2011 Author Share Posted April 1, 2011 Your css is working fine... it's your scriptingWhen you click on billing and then invoices the current class name is assigned to clientarea instead of billing. My issue is, though, that the nav is contained within the header.tpl file, so I need some way to dynamically change it. I cannot assign a class for every page because of this. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.