21491 Posts in 5783 Topics by 2621 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1638 Views |
-
renderWith nested arrays

20 April 2010 at 8:29pm
Hi.
I'm trying to render an Ajax response with a specified template.My controller code looks like this:
$data = array(
'Items' => array( 'Test1', 'Test2', 'Test3' ),
'Pairs' => array( 'Foo' => 'Bar' ),
);
return $this->customise($data)->renderWith('AjaxResponse');Now, in the template, I can use the control Items to get the iterator:
<% control Items %>
<item />
<% end_control %>So it prints three separate items, but I am unable to get their contents.
How can I print out 'Test1','Test2','Test3' in Items control?
I also tried to use $Pairs.Foo, but it still didn't work.
So I've got two questions:1. How should I construct the $data array to use it as controls in the template?
2. Is it possible to get the keys, not only values, from a control? -
Re: renderWith nested arrays

21 April 2010 at 12:06pm
Try this:
// . . .
$items = new DataObjectSet();
foreach( array('Test1', 'Test2') as $text) {
$items->push( new ArrayData( array('Content' => $text ) ) );
}
$data = array(
'Items' => $items,
'Pairs => array( 'Foo' => 'Bar' )
);
// . . .Then your template should be able to do:
<% control Items %>
<item>$Content</item>
<% end_control %>
$Pairs.FooThis should work, in theory..
Cheers
- Luke -
Re: renderWith nested arrays

22 April 2010 at 2:50am Last edited: 22 April 2010 2:53am
Works perfect, thanks a lot!
And for getting the keys, not only values, from a control - I changed it to:foreach($arr as $key => $val) {
$data->push(new ArrayData( array( 'Key' => $key, 'Value' => $val ) ));
}So now I can use:
<% control Items %>
<item id="$Key"><![CDATA[$Value]]></item>
<% end_control %>Thank you very much!
| 1638 Views | ||
|
Page:
1
|
Go to Top |

