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.

General Questions /

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

Access array elements with <% control %>


Reply


3 Posts   421 Views

Avatar
Josua

Community Member, 86 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, 5513 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, 86 Posts

7 March 2012 at 6:35am

Hi Willr!

Yes. This works perfectly.
Thanks!!

Regards,
Jose