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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Looping without object


Go to End


1233 Views

Avatar
lulu

Community Member, 7 Posts

14 November 2016 at 10:31pm

Hi all,

I was just wondering if it's possible to loop in template but without any object - just loop alone, of instance I have a following code:

            <div class="row">
                <div class="medium-3 small-6 columns">
                    <img class="mb10" alt="$FigureT1" title="$FigureT1" src="$FigureI1" />
                    <p>$FigureT1</p>
                </div>
                <div class="medium-3 small-6 columns">
                    <img class="mb10" alt="$FigureT2" title="$FigureT2" src="$FigureI2" />
                    <p>$FigureT2</p>
                </div>
                <div class="medium-3 small-6 columns">
                    <img class="mb10" alt="$FigureT3" title="$FigureT3" src="$FigureI3" />
                    <p>$FigureT3</p>
                </div>
                <div class="medium-3 small-6 columns">
                    <img class="mb10" alt="$FigureT4" title="$FigureT4" src="$FigureI4" />
                    <p>$FigureT4</p>
                </div>
            </div>

And I think it would be much easier now to loop through it like this:

	<div class="row">
		<% loop.Count(4) %>
			<div class="medium-3 small-6 columns">
				<img class="mb10" alt="$FigureT$Pos" title="$FigureT$Pos" src="$FigureI$Pos" />
				<p>$FigureT$Pos</p>
			</div>
		<% end_loop %>
	</div>

I've made up of course loop.Count(4) - but is there anything like this in Silver Stripe by the chance?

I have few instances in my templates where this could be useful.

Many thanks, L.