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.

Template Questions /

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

Controller functions inside a control loop


Go to End
Reply


4 Posts   1050 Views

Avatar
vegetav

Community Member, 23 Posts

15 March 2012 at 2:20am

Edited: 15/03/2012 2:59am

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?

Avatar
swaiba

Forum Moderator, 1830 Posts

15 March 2012 at 3:03am

how about...

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

Avatar
JonoM

Community Member, 119 Posts

15 March 2012 at 3:05am

Edited: 15/03/2012 3:06am

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!

Avatar
vegetav

Community Member, 23 Posts

15 March 2012 at 5:56am

That works great thanks :)