CodeIgniter Forums
achor highlighting - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: achor highlighting (/showthread.php?tid=9052)



achor highlighting - El Forum - 06-10-2008

[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


achor highlighting - El Forum - 06-10-2008

[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!


achor highlighting - El Forum - 06-10-2008

[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


achor highlighting - El Forum - 06-10-2008

[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 :-)


achor highlighting - El Forum - 06-10-2008

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