Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6158439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:57:27+00:00 2026-05-23T20:57:27+00:00

I am trying to populate four menu items in Silverstripe. I have managed to

  • 0

I am trying to populate four menu items in Silverstripe. I have managed to populate the first two menu items with SS using li class=”area{$Pos}” in one div. However, the third and fourth menu items are in different div and class from the first two. I’ve been searching but not sure how to use SS to populate the third and fourth menus items in different div(/second div> and class? Sorry I’m new to it, so any help would be appreciated.

Here is my code.

<div id="top">
<ul class="sf-menu">
     <% control Menu(1) %>
       <li id="area{$Pos}">
        <a href="#a">$MenuTitle</a>
           <% if Children %>
                 <ul><% control Children %>
                        <li>
                           <a href="#aa">$MenuTitle</a>

                         <% if Children %>
                            <ul>
                            <% control Children %>
                                 <li>
                                 <a href="#aa">$MenuImg.SetSize(20,20) $MenuTitle</a>
                                  </li>
                            <% end_control %>
                            </ul>
                        <% end_if %>
                       </li>
                   <% end_control %>

                </ul><% end_if %>

          </li>
         <% end_control %>

</ul>
</div>

<div id="test" >
<ul class="sf-menu sf-vertical">
      <li id="area3">
      <a href="#a">Area 3</a>
      </li>

      <li id="area4">
      <a href="#">Area 4</a>
        <ul class="show_left">
          <li>
           <a href="#">Store one</a>

          </li>
          <li>
           <a href="#">Store Two</a>

          </li>

       </ul>
    </li>
</ul>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:57:28+00:00Added an answer on May 23, 2026 at 8:57 pm

    you’re already using the $Pos Control (see the docs) in your code, you can also use it inside an ‘if’ block.
    this should do the trick (untested):

    BEWARE this snippet doesn’t work as expected. see the UPDATE below

    <% control Menu(1) %>
    <% if Pos == 1 || Pos == 2 %>
    <div>render items 1 and 2 here</div>
    <% end_if %>
    <% end_control %>
    
    <% control Menu(1) %>
    <% if Pos == 3 || Pos == 4 %>
    <div>render items 3 and 4 here</div>
    <% end_if %>
    <% end_control %>
    

    just note that <% if Pos < 3 %> syntax isn’t supported.
    for a cleaner way to do the same thing, refer to this snippet on ssbits.

    UPDATE

    unfortunately, silverstripe doesn’t seem to support more complex conditions as above either.
    this one is supported (as in the docs):

    <% if MyBoolean || MyOtherBoolean %>
    

    whereas this one isn’t:

    <% if MyInteger == 1 || MyInteger == 2 %>
    

    so, the best solution seems to be the second one i pointed you too (the snippet on ssbits above).
    in your case, this could read as follows:

    add functions to the ‘Page’ class you’re using to check the current position:

    public function InFirstDiv() {
      return ($this->iteratorPos == 1 || $this->iteratorPos == 2);
    }
    public function InSecondDiv() {
      return ($this->iteratorPos == 3 || $this->iteratorPos == 4);
    }
    

    then, call them in your template:

    <% control Menu(1) %>
    <% if InFirstDiv %>
    <div>render items 1 and 2 here</div>
    <% end_if %>
    <% end_control %>
    
    <% control Menu(1) %>
    <% if InSecondDiv %>
    <div>render items 3 and 4 here</div>
    <% end_if %>
    <% end_control %>
    

    doesn’t look very smart – but should work this time 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to populate an asp:Menu control using an XML file. I want
I'm lost trying to create and populate arrays. I have four wrapper panels, which
I'm trying to populate a field called 'identification' using the primary key 'id'. However,
I am trying to populate variables in the Report Custom Code area (or even
I'm trying to populate a class object with values from a database table. The
I'm trying to populate a smartgwt calendar using data form a server obtained using
I am trying to populate a string with a double value using a sprintf
I am trying to populate a list box from a list in python using
I am trying to populate a datagrid with one column as a combobox but
I am trying to populate an excel spreadsheet using VBA (is actually something different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.