A background image is specified in the css and the first and last items differ (mainNavLeft and mainNavRight). Is it possible to specify these in the xslt file? I assume I can using an if statement but I'm not sure how to target the specic item?
That code should be displaying things, the if statements shouldn't matter as to whether the middle list items get displayed.
You need to do a choose rather than an if as with yours right now the first and last elements will have two li's in your current code (as that middle li will always appear even if you show extras for the first and last):
Using the code above, your nav items will be written out twice on the first and last times, as it will write the middle list item as well as whatever is true for the if conditions. Also, using $currentPage/node will only give output when the current page has children, so this would work e.g. for your homepage but not for any child pages.
Something like the following might be better. I've put only the id definitions into the if statements to avoid duplication
Great thread I'm trying to do something similar expect i want each item on my Nav li to get a unique class so the XLST output like this...or is there a way i can pick up the loop number?
Please don't do double posting, since it can become quite confusing at a later stage. I understand that you appreciate a quick answer and fortunately most times people actually are quite quick at getting back to you - if not it's sometimes very efficient to write about your issue on twitter using the #umbraco hashtag.
Is it possible to specify a class for first and last navigation item?
Hi,
Essentially, my navigation looks like this...
A background image is specified in the css and the first and last items differ (mainNavLeft and mainNavRight). Is it possible to specify these in the xslt file? I assume I can using an if statement but I'm not sure how to target the specic item?
Thanks,
Rachel
Rachel,
you can use position() = 1 and position() = last() to get these items from a set of iterated nodes
Hope this helps.
Regards,
/Dirk
Hi Dirk, thank you for your response.
I am trying the following but it is not displaying anything on my page...
Do I need to add an if statement to the list items that will be in the middle of the navigation?
Thanks,
Rachel
Try this:
Rachel,
That code should be displaying things, the if statements shouldn't matter as to whether the middle list items get displayed.
You need to do a choose rather than an if as with yours right now the first and last elements will have two li's in your current code (as that middle li will always appear even if you show extras for the first and last):
Hi Rachel
Using the code above, your nav items will be written out twice on the first and last times, as it will write the middle list item as well as whatever is true for the if conditions. Also, using $currentPage/node will only give output when the current page has children, so this would work e.g. for your homepage but not for any child pages.
Something like the following might be better. I've put only the id definitions into the if statements to avoid duplication
Dan
Wow, a smorgasbord of useful answers!
hmm, not displaying anything.. time for some extra checks...
what if you just use
Does that display anything. If not, then your select in for loop doesn't generate results.
On the other hand, maybe be better to swith to another construct
(your construct currently will output first and last items twice)
Cheers,
/Dirk
Hehe, yeah - fast responses for sure! @dandrayne: that approach will leave an empty id attribute on all anchors except first and last.
Sure lots of useful and even better answers... wow, what a community...
Woo hoo - thanks guys! I've used the code Kenneth posted and it works perfectly.
Now I just need to try and get my 2nd level navigation to work - I may be back....!!
Cheers,
Rachel
Great thread I'm trying to do something similar expect i want each item on my Nav li to get a unique class so the XLST output like this...or is there a way i can pick up the loop number?
<ul>
<li class="link1"><a href="#">Home page</a></li>
<li class="link2" ><a href="#">Services</a></li>
<li class="link3" ><a href="#">Insulation Grants</a></li>
<li class="link4" ><a href="#">Solar PV</a></li>
<li class="link5" ><a href="#">The Green deal</a></li>
<li class="link6" ><a href="#">Book Appointment</a></li>
<li class="link7" ><a href="#">About us</a></li>
</ul>
@Stephen: See my answer in the other thread — but yes, position() will give you the "loop number" for the active element.
Hi Stephen
I believe there is already an answer for you in the post you created about the subject yourself here: http://our.umbraco.org/forum/developers/xslt/32594-Specify-a-unique-class-for-each-menu-item?p=0#comment119732 :)
Please don't do double posting, since it can become quite confusing at a later stage. I understand that you appreciate a quick answer and fortunately most times people actually are quite quick at getting back to you - if not it's sometimes very efficient to write about your issue on twitter using the #umbraco hashtag.
Cheers,
Jan
Sorry Jan, just thought this was a relavent subject matter...knuckles rapped and acknowledged! :-)
S
is working on a reply...