Welcome Guest, Not a member yet? Register   Sign In
achor highlighting
#1

[eluser]soupdragon[/eluser]
I am sure this has been asked before but i have failed to find the answer

i have a side navi which i include as a view all over the place.
in it obviously lots of this sort of thing

<?=anchor('start/help', 'Hilfe', 'onfocus="blur()"');?>

i have in the controllers a $data['page] so know where i am but
how can i easily highlight which navi point i am on ?


so far i have come up with this
<li>&lt;?=($page == 'help') ? '<b>' : '';?&gt;&lt;?=anchor('start/help', 'Hilfe', 'onfocus="blur()"');?&gt;&lt;?=($page == 'help') ? '</b>' : '';?&gt;</li>

but to be honest thats more code than if i just hard coded the link :-P
#2

[eluser]Gavin Blair[/eluser]
This may be slightly shorter:

<li>&lt;?php if($page=='help') $attributes = array( 'class' => 'current' ); echo anchor('start/help', 'Hilfe', $attributes); ?&gt;</li>

(in your css, make sure .current { font-weight: bold; } )

But I tend to use html anchors:

<li><a href="&lt;?=base_url()?&gt;index.php/start/help" class="&lt;?=($page == 'help') ? 'current' : '' ?&gt;">Hilfe</a>

This is the shortest and seems the easiest to read.

Hope this helps!
#3

[eluser]soupdragon[/eluser]
yep we are thinking along the same lines !

i'm thinking $attributes = $spoon = array('title' => 'val1', 'onfocus' => '"blur()"', 'id' => $page.'x');

and then a css rule with bold for all pages
#4

[eluser]soupdragon[/eluser]
and in fact i just need once at the top of the side nav

$attributes = array( 'onfocus' => '"blur()"', 'id' => $page.'x');

and then each anchor becomes

&lt;?=anchor('start/help', 'Hilfe', $attributes);?&gt;

so in fact shorter than before :-)
#5

[eluser]Gavin Blair[/eluser]
ooh clever! I'll have to give that a try




Theme © iAndrew 2016 - Forum software by © MyBB