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

<% loop %> question


Go to End


2 Posts   1291 Views

Avatar
Kutten

Community Member, 1 Post

18 June 2015 at 8:04am

I wanted to create a list of files using a loop and but it doesn't work. If I change the 'loop' for an 'if' it works but I need it to loop.

<% loop $MyFile %>
<li><a href="$MyFile.URL">
Download $MyFile.Name [$MyFile.Size]
</a></li>
<% end_loop %>

Not entirely sure this is a template issue as I can upload multiple files in the CMS but it only remembers the first, but I'm under the impression that's a separate issue.

Cheers

Avatar
Pyromanik

Community Member, 419 Posts

18 June 2015 at 11:28am

Edited: 18/06/2015 11:30am

Seems to me like it's probably the same issue. It sounds like you've got a has_one relationship instead of a many_many (or a has_many to an intermediary object - see the tutorials for info on this).

It would be only saving a single object because it only relates to one object. Then in your template you think you're expecting a list, when you've actually got just a singular object (not in a list).