Jump to:

23555 Posts in 19382 Topics by 2892 members

General Questions

SilverStripe Forums » General Questions » Access array elements with <% control %>

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

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

Page: 1
Go to End
Author Topic: 390 Views
  • Josua
    Avatar
    Community Member
    86 Posts

    Access array elements with <% control %> Link to this post

    Hello!

    Can I access the elements of an array with a <% control %> structure?

    If

    protected function RArray() {
    return array("foo1" => "bar1", "foo2" => "bar2");
    }

    then

    <% control RArray %>
    ???????
    <% end_control %>

    What should I use to access the array elements?

    Thanks,

    Regards,
    Jose

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Access array elements with <% control %> Link to this post

    You can, but you need to wrap the array in an Array Data object.

    return new ArrayData(array(
    'Hi' => 'Hello'
    ));

  • Josua
    Avatar
    Community Member
    86 Posts

    Re: Access array elements with <% control %> Link to this post

    Hi Willr!

    Yes. This works perfectly.
    Thanks!!

    Regards,
    Jose

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