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

Access array elements with <% control %>


Go to End


3 Posts   805 Views

Avatar
Josua

Community Member, 87 Posts

6 March 2012 at 10:05am

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

Avatar
Willr

Forum Moderator, 5523 Posts

6 March 2012 at 6:21pm

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

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

Avatar
Josua

Community Member, 87 Posts

7 March 2012 at 6:35am

Hi Willr!

Yes. This works perfectly.
Thanks!!

Regards,
Jose