17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2227 Views |
-
$Pos in image url

9 July 2008 at 2:59pm
Hello, I'm pretty new to SS, but I'm loving it.
I'm trying to loop through the children of a page but I want to display some sequential images, like
but that doesn't work. It ends up just doing<img src="number$Pos.jpg" />
<img src="number.jpg" />
Any ideas? Thanks!
-
Re: $Pos in image url

9 July 2008 at 4:47pm
because number$Pos is 1 string you might need to try and wrap the $Pos in a {} so it would be
number{$Pos}
Try that and see if it works
-
Re: $Pos in image url

10 July 2008 at 12:21am
One more thing. I want to only get the first 4 children, how can I do that? I tried this:
<% control ChildrenOf(page-url) %>
<% if $Pos < 5 %>
....
<% end_if %>
<% end_control %>but that didn't work. Just got a blank screen, which probably means there was a php error but they're turned off.
Thanks
-
Re: $Pos in image url

14 July 2008 at 5:07pm
Yeah the template language was kept simple so that logic would be necessarily kept out of the templates.
The best way to solve this is to create another small data handler method on your controller:
function MyList() {
$parent = DataObject::get_one('SiteTree', "URLSegment = 'my-page'");
return DataObject::get("SiteTree", "ParentID = $parent->ID", "", "", "4");
}Then you can just use <% control MyList %> in your template.
The advantage of this approach is that you can focus on layout in your template file, and the exact details by which data is selected in your MyList() function. If you wanted to give template designers the flexibility to decide how many pages, to show, you could have an argument to the MyList function
function MyList($limit = 4) {
$parent = DataObject::get_one('SiteTree', "URLSegment = 'my-page'");
return DataObject::get("SiteTree", "ParentID = $parent->ID", "", "", $limit);
}Then you can just use <% control MyList(4) %> in your template. Since we've set a default value for the $limit argument, you could also use <% control MyList %>.
| 2227 Views | ||
|
Page:
1
|
Go to Top |



