3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 352 Views |
-
How to iterate through an Arraylist within an array list?

19 December 2012 at 10:47pm
How can I loop through an ArrayList within another ArrayList?
I tried a lot of things and was looking all over the Silverstripe sites, but somehow I can't figure out how this works.
Anybody can give me some clue?This is what I have now:
Function inside controller:
$pages = DataObject::get("SiteTree","MATCH (Title, Content) AGAINST ('$query' IN BOOLEAN MODE)");
$searchresults = new ArrayList(array(
'pages' => $pages
));$data['Results'] = $searchresults;
return $this->customise($data)->renderWith(array('Page_results'));
Template:
<% if Results %>
<ul id="MainSearchResults">
<% loop Results %>
<% if pages() %>
<% loop pages() %>
<li>
<a class="searchResultHeader" href="$Link">
<% if MenuTitle %>
$MenuTitle
<% else %>
$Title
<% end_if %>
</a>
<p>$Content.LimitWordCountXML</p>
<a class="readMoreLink" href="$Link" title="Lees meer over "{$Title}"">Lees meer over " {$Title}"...</a>
</li>
<% end_loop %>
<% else %>
<p>There are no results</p>
<% end_if %><% end_loop %>
</ul>
<% else %>
<p>Sorry, there are no results</p>
<% end_if %> -
Re: How to iterate through an Arraylist within an array list?

20 December 2012 at 12:00am
In your example, $pages is a DataList, so you don't need to wrap it in an ArrayList.
Just do $data['Results'] = $pages and in your template:
<% if Results %>
<% control Results %>
etc
<% end_control %>
<% else %>
There were no results
<% end_if %> -
Re: How to iterate through an Arraylist within an array list?

20 December 2012 at 1:25am
@kinglozzer: thanks for your quick response. In my example I had only one list inside a list, but in fact I want to use several lists inside the Arraylist, so my question remains the same...
-
Re: How to iterate through an Arraylist within an array list?

20 December 2012 at 3:33am
Why the parentheses after pages? Have you tried removing them?
Also why not show the name of your controller function. Did you call it pages maybe?
| 352 Views | ||
|
Page:
1
|
Go to Top |


