Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Drop down menu with class applied to only one link

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

Page: 1
Go to End
Author Topic: 1357 Views
  • Roweena
    Avatar
    Community Member
    28 Posts

    Drop down menu with class applied to only one link Link to this post

    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?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Drop down menu with class applied to only one link Link to this post

    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

  • Roweena
    Avatar
    Community Member
    28 Posts

    Re: Drop down menu with class applied to only one link Link to this post

    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 %>
       

    1357 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.