Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Custom external links within navigation control

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

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

Page: 1
Go to End
Author Topic: 1613 Views
  • Andrew Houle
    Avatar
    Community Member
    132 Posts

    Custom external links within navigation control Link to this post

    I want to link to external pages within my navigation. Is it possible to check the urlsegment within the control loop? Something like this:

    <ul class="ir nav">
       <% control Menu(1) %>   
          <li class="ir-$URLSegment"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><em>$MenuTitle</em></a>
             
             <ul id="sub-$URLSegment">
                <% control Children %>
                   <li><a href="$Link">$MenuTitle</a></li>
                   
                <% end_control %>
                <% if $URLSegment="admissions" %>
                <li><a href="#">Test Link</a></li>
                <% end-if %>
             </ul>
          
          </li>
       <% end_control %>
    </ul>

    Basically I want to use the $URLSegment variable to test if I'm on the admissions page, and if so print links accordingly.

    Thanks for the help.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Custom external links within navigation control Link to this post

    yes, but withing <% %> tags, you drop the dollar sign and the quotes. Also use == instead of =.

    ie:

    <% if URLSegment == admissions %>
    <li><a href="#">Test Link</a></li>
    <% end_if %>

  • Andrew Houle
    Avatar
    Community Member
    132 Posts

    Re: Custom external links within navigation control Link to this post

    Perfect! That works great, thanks for your help!

  • Andrew Houle
    Avatar
    Community Member
    132 Posts

    Re: Custom external links within navigation control Link to this post

    I just realized my logic is screwy. I need the navigation to add links to external pages. For instance, the prior logic only added the "Test Link" where URLSegment == admissions. I need it to add that test link all the time under the admissions navigation. Is that possible? I'll keep looking.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Custom external links within navigation control Link to this post

    Move it into the control loop. At the moment you have it outside of the control loop.

  • Andrew Houle
    Avatar
    Community Member
    132 Posts

    Re: Custom external links within navigation control Link to this post

    Unfortunately even though that logic seems better, the "Test Link" doesn't appear in the menu. Here is what my code looks like now:

    <ul class="ir nav">
       <% control Menu(1) %>   
          <li class="ir-$URLSegment"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><em>$MenuTitle</em></a>
             
             <ul id="sub-$URLSegment">
                <% control Children %>
                   <li><a href="$Link">$MenuTitle</a></li>
                   <% if URLSegment == admissions %>
                      <li><a href="#">Test Link</a></li>
                   <% end_if %>
                <% end_control %>
                
             </ul>
          
          </li>
       <% end_control %>
    </ul>

    Sorry to keep this going, I was just hoping this sort of thing would be rather simple.

    Thanks again for your help!

    1613 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.