Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » Controller functions inside a control loop

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

Page: 1
Go to End
Author Topic: 738 Views
  • vegetav
    Avatar
    Community Member
    23 Posts

    Controller functions inside a control loop Link to this post

    I'm sure this has been covered a few times but I'm unable to find a solution to what I think should be a fairly simple problem.

    Here is my basic code...

    <% control Menu(1) %>
       <li>
          <a href="$Link" title="$Title">$MenuTitle</a>
          <% if Children %>
             <div class="sub-nav">
                <ul>
                   <% control Children %>
                   <li>
                      <a href="$Link" title="$Title">
                         $MenuTitle <br/>
                         <span>$MenuDesc</span>
                      </a>
                   </li>
                   <% end_control %>
                </ul>
             </div>
          <% end_if %>
       </li>
    <% end_control %>

    I need to add a class to the <li> on the 6th child inside <div class="sub-nav">, which in theory I can to in a function within the Page_Controller, however I can't call these functions from within a <% control %> loop. Does anyone know a work around for this?

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Controller functions inside a control loop Link to this post

    how about...

    <% control Children %>
       <li <% IsMultipleOf(6) %>something<% end_if %>>
          <a href="$Link" title="$Title">
             $MenuTitle <br/>
             <span>$MenuDesc</span>
          </a>
       </li>
    <% end_control %>

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: Controller functions inside a control loop Link to this post

    Would <% if MultipleOf(6) %> work for you? See Modulus and MultipleOf http://doc.silverstripe.org/sapphire/en/reference/advanced-templates
    Edit: Swaiba bet me to the punch!

  • vegetav
    Avatar
    Community Member
    23 Posts

    Re: Controller functions inside a control loop Link to this post

    That works great thanks

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