Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

CSS Sprites and Silverstripe


Reply


4 Posts   1395 Views

Avatar
UncleCheese

Forum Moderator, 4096 Posts

18 September 2007 at 9:12am

Edited: 18/09/2007 9:13am

Using the Menu control, how can I add a unique ID to every LI tag that gets printed? If I use the $Title or $MenuTitle variables, I end up with spaces in the name, and if I use $Link, I end up with slashes in the name, all of which are invalid. Any ideas? Is there a variable available that outputs the current iteration of the loop? Or maybe the URL text of the page without the slashes? How is this usually done?

Thanks.

Avatar
Andy

230 Posts

18 September 2007 at 9:35am

You can use $URLSegment

Avatar
Matt

Core Development Team, 84 Posts

18 September 2007 at 7:16pm

Depending on what I'm doing, I'll use $URLSegment, $ID or $Pos... I can't remember if $Pos was something I hacked in or not, it's quite possible that it is (it returns the nth item in the list, e.g. 3 for the third item etc).

$ID returns the database ID of the current page/data object. Obviously, you can't use these on their own, I normally prefix them with a descriptor - e.g. <li id="Booking_$ID"> or similar.

Avatar
UncleCheese

Forum Moderator, 4096 Posts

19 September 2007 at 1:21am

Wow.. this is great. Thanks, guys. How do you know all those template variables? If I had a list of all of those, I could have figured it out, but I looked everywhere. Any leads?