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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Drop down menu with class applied to only one link


Go to End


3 Posts   2225 Views

Avatar
Roweena

Community Member, 28 Posts

24 February 2009 at 10:50am

I'm trying to get my navigation to work on Silver Stripe, it works perfectly well in my test html pages. What I need to do is assign the class head to the navigation menu link that has children, the html code is as follows:

<div id="navigationTop">
<ul>
<li><a href="about.php" class="current">About</a></li>
<li>
<a href="holistic-approaches.php" class="head">Holistic Approaches</a>
<ul>
<li><a href="readings.php">Readings</a></li>
<li><a href="reiki.php">Reiki</a></li>
<li><a href="healing.php">Healing</a></li>
</ul>
</li>
<li><a href="life-coaching.php">Life Coaching</a></li>
<li><a href="workshops.php">Workshops &amp; Courses</a></li>
<li><a href="">Testimonials</a></li>
<li><a href="">Events</a></li>
<li><a href="">News</a></li>
</ul>
</div>

My silver stripe code is:

<div id="navigationTop">
<ul>
<% control Menu(1) %>
<li>
<a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle</span></a>
<% if Menu(2) %>
<ul>
<% control Menu(2) %>
<li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title}&quot; page">$MenuTitle</a></li>
<% end_control %>
</ul>
<% end_if %>

</li>
<% end_control %>
</ul>
</div>

What I'm trying to do is get the class "head" into the following line after the class applied to $LinkingMode and I've tried various if statements to do this, eg:
<a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode <% if Title="Holistic Approacges" %>head<% end_if %>
"><span>$MenuTitle</span></a>

but this doesn't work.
How can I do this?

Avatar
Carbon Crayon

Community Member, 598 Posts

25 February 2009 at 3:46am

Edited: 25/02/2009 3:46am

Hi Roweena, welcome to Silverstripe :)

If I understand you just want to apply a custon class to top level links which have children?

You should be able to do this by just moving your top level link to inside the menu(2) if statment like this:

<ul>
<% control Menu(1) %>
<li>
<% if Menu(2) %>
<a class="head" href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle</span></a>
<ul>
<% control Menu(2) %>
<li class="$LinkingMode"><a href="$Link" title="Go to the "{$Title}" page">$MenuTitle</a></li>
<% end_control %>
</ul>
<% else %>
<a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle</span></a>
<% end_if %>
</li>
<% end_control %>
</ul>

I havn't tried it bit it should do the trick

Avatar
Roweena

Community Member, 28 Posts

25 February 2009 at 7:43am

Thanks again for your help. For some reason Menu2 was just never getting recognised so I've ended up with the following code and this works fine...
<ul id="Menu1">
<% control Menu(1) %>
<% if Children %>
<li class="$LinkingMode"><a href="$Link" class="head"><span>$MenuTitle</span></a>

<ul>
<% control Children %>
<li><a href="$Link" class="$LinkingMode">$MenuTitle</a></li>
<% end_control %>
</ul>
</li>
<% else %>
<li class="$LinkingMode"><a href="$Link"><span>$MenuTitle</span></a></li>
<% end_if %>