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.

Template Questions /

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

Reference subarray data from template (SS 2.4)


Go to End


3 Posts   1447 Views

Avatar
kharmer

Community Member, 8 Posts

28 February 2013 at 3:51am

Edited: 28/02/2013 4:52am

Hi All,

I am quite new to SS, so this might be a silly question!

I have in my template a dataset that, when dumped to screen, looks like this:

Array
(
....[0] => ArrayData Object
........(
............[array:protected] => Array
................(
....................[FirstName] => Agent 1
....................[LastName] => Agent 1
....................[AgentDistributor] => Distributor 1
....................[products] => Array
........................(
............................[0] => Array
................................(
....................................[ProductID] => 11
....................................[ProductName] => Product1
....................................[Quantity] => 15
................................)

............................[1] => Array
................................(
....................................[ProductID] => 11
....................................[ProductName] => Product1
....................................[Quantity] => 15
................................)

........................)

................)

............[iteratorPos:protected] => 
............[iteratorTotalItems:protected] => 
............[failover:protected] => 
............[customisedObject:protected] => 
............[objCache:ViewableData:private] => Array
................(
................)

............[class] => ArrayData
............[extension_instances:protected] => Array
................(
................)

........)

....[1] => ArrayData Object
........(
............[array:protected] => Array
................(
....................[FirstName] => Agent 2
                    ............

Now, using <% control AgentsResults %> I can loop through the data as expected. However, I am trying to loop through the products sub-array using a nested <? control ?>. Of course this doesn't work, hence I am here.

I found references to <? control Children ?> but this doesn't appear to work!

Could anyone suggest the correct way to go about this, taking into account I am forced to run SS 2.4!

Best regards,
K...

Avatar
Willr

Forum Moderator, 5523 Posts

28 February 2013 at 8:56pm

Products should be wrapped in an ArrayList object so it's iterable. Once you do that, you can do <% control Products %>

Avatar
kharmer

Community Member, 8 Posts

6 March 2013 at 4:17am

Thanks Willr - thats was enough to get me moving again. All sorted now thanks.

K...