Jump to:

3432 Posts in 1025 Topics by 865 members

Template Questions

SilverStripe Forums » Template Questions » Reference subarray data from template (SS 2.4)

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

Page: 1
Go to End
Author Topic: 474 Views
  • kharmer
    Avatar
    Community Member
    8 Posts

    Reference subarray data from template (SS 2.4) Link to this post

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

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Reference subarray data from template (SS 2.4) Link to this post

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

  • kharmer
    Avatar
    Community Member
    8 Posts

    Re: Reference subarray data from template (SS 2.4) Link to this post

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

    K...

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