Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » Iterate through all fields of one record

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

Page: 1
Go to End
Author Topic: 843 Views
  • MattB
    Avatar
    Community Member
    7 Posts

    Iterate through all fields of one record Link to this post

    Hi all,

    I'd like to iterate through all the fields of a single record in an SS template. As a simple example, I'm trying to automatically output all the fields of a Member record.

    SomePage_Controller.php

    function MemberData() {
    return Member::CurrentUser();
    }

    SomePage.ss

    <% control MemberData %>
    <% control Children %>
    $key: $value
    <% end_control %>
    <% end_control %>

    I've tried various permutations of returning DataObject, GetIterator(), ArrayData(), DataObject::database_fields, DataObjectSet, but I'm unable to find any way to iterate through the fields as Children (or otherwise)...

    Would very much appreciate some extra brains on this one... any guidance?

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Iterate through all fields of one record Link to this post

    how about...

    SomePage_Controller.php

    function MemberFields() {
       return Member::CurrentUser()->getCMSFields();
    }

    SomePage.ss

    <% control MemberFields %>
       $Title $Value
    <% end_control %>

    (note untested)

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