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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[Solved] How to display items from GridField


Go to End


3 Posts   699 Views

Avatar
Vlad Belfort

Community Member, 55 Posts

7 April 2016 at 4:39am

I have some items in GridField which I want listed in that page types template.

How do I do this??

Avatar
Vix

Community Member, 60 Posts

8 April 2016 at 3:01pm

Assuming you have a relationship set up called 'GridFieldItems' eg:

private static $has_many = array(
		'GridFieldItems' => 'GridFieldItem'
	);

You can access that relationship in the template with:

<% if GridFieldItems %>
  <% loop GridFieldItems %>
   do something...
  <% end_loop %>
<% end_if %>

Avatar
Vlad Belfort

Community Member, 55 Posts

8 April 2016 at 9:38pm

Edited: 08/04/2016 9:42pm

I've tried that but all it does is output 1 thing as there's one GridField item...

So for example

    <% loop MailingList %>
        $Email :):):)
    <% end_loop %> 

Will output

:):):)

It doesn't actually access the data, just does 1 loop because theres one GridField item and that's it

---
Edit
OOOHHHH it worked after I put in the 's' to MailingList haha

Thanks for the help!