21297 Posts in 5734 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 229 Views |
-
Looping in loop

28 February 2012 at 8:28am
<% control AllChildren %>
<div class="map_item">
<h1 class="$Color">$Title</h1><div class="image">$Photo</div>
<ul>
<% control MyLoopFunction(2) %>
<li><a href="$Link">$Title</a></li>
<% end_control %>
</ul>
</div>
<% end_control %>In this example MyLoopFunction is not working. But MyLoopFunction working without looping AllChildren
<ul>
<% control MyLoopFunction(2) %>
<li><a href="$Link">$Title</a></li>
<% end_control %>
</ul>Please help me anyone
sorry for my English
-
Re: Looping in loop

28 February 2012 at 10:24pm
Hi orkhan, welcome to the forums
I assume MyLoopFunction() is a function in your Page_Controller? That will not work within the <% control AllChildren %> loop because it returns a set of Page objects (the data model class), not Page_Controllers. So in order for this to work, you'd have to define the MyLoopFunction() funtion in your Page class instead.
-
Re: Looping in loop

28 February 2012 at 10:47pm
<?php
class Applications extends SiteTree {
....
}
class Applications_Controller extends ContentController {
.....
function MyLoopFunction($id=1) {
$children = DataObject::get("SolutionsPage", '`SolutionsPage_AppsTypes`.`AppsTypeID` = '.$id, "Created DESC", "LEFT JOIN `SolutionsPage_AppsTypes` ON `SolutionsPage_AppsTypes`.`SolutionsPageID` = `SolutionsPage`.`ID`", 100);return $children;
}
}This is my Applications class extends to SiteTree
What there is not true?
-
Re: Looping in loop

28 February 2012 at 11:09pm
What there is not true?
As martimz says - context is wrong. Control is not just a "loop" but also changes "context" you start out int he Page_Controller object, then you move context into the Page object. This is changing to be more clear in SS3.
Just try moving your function from "Applications_Controller" to "Applications" and see what happens...
-
Re: Looping in loop

28 February 2012 at 11:30pm
Thanks it is worked. But when i try change my code to this
<% control ChildsLoop(Pos) %>
result is
Sorry, there was a problem with handling your request.how to fix it?
-
Re: Looping in loop

28 February 2012 at 11:45pm
you can only pass fixed strings into methods on the template - whereas $Pos may provide a number when merged it cannot be used as a function paramter.
This comes up over and over, so I have a post to refernce for you now...
http://www.silverstripe.org/template-questions/show/13619#post304007#post304007
| 229 Views | ||
|
Page:
1
|
Go to Top |


Please close topic 