17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2287 Views |
-
generate tables in template

14 November 2007 at 8:11pm
Hello everybody,
I'm still quite new to Silverstripe - But am quite enthusiastic about it.
I have one question. Imagine i have something similar to the newssection as created in the tutorial, but now I want to show it in a table.
So instead of all items being iterated, and show below each other, i want to create table cells. And that's easy, but i can't find how to automatically insert a new table row after let's say each 3 cells.Below I have the control code from the template. And this is working, except I need to generate every 3 <td></td> and additional </tr><tr>.
<table>
<tr>
<% control Children %>
<td>
<p>$Pos - $Title</p>
<p>$Iterator</p>
<embed src="$URL" type="application/x-shockwave-flash" width="200" height="173" allowFullScreen="true"></embed><br />
<% if NewRow %>
<p>tsja - en nu is newrow true</p>
<% else %>
<p>tsja - en nu is newrow false</p>
<% end_if %></td>
<% end_control %>
</tr>
</table>hope someone can give me some help
Thanks
Bas -
Re: generate tables in template

25 November 2007 at 12:17pm Last edited: 25 November 2007 12:18pm
Can you not move the <tr> and </tr> elements inside the <% control Children %> block?
Oh, but then each child would have a <tr>... Hmm, you'll probably need a custom method to generate this table for you.
Sean
-
Re: generate tables in template

25 November 2007 at 4:15pm
any reason why you need to use a table? Couldn't you still use a list, Give the unordered list a width, Give each list item a width (1/3 of the ul) , float the list items. Hopefully then you will have 3 columns and no need for a custom method to generate the table which could be interesting to achieve.
-
Re: generate tables in template

25 November 2007 at 10:53pm
Quite true. Tables are a pain to style as well, especially adding borders to <tr> which is inconsistent across browsers.
Sean
-
Re: generate tables in template

26 November 2007 at 10:38am
thanks for the input
I can try to do it with the ul
But i'm also really curious how i can do something like that. I was thinking that i can maybe make a function in the controller to give me a row of 3 every time - but even then it's hard to get it working good - including pagination.For now i've solved it by just having one column -but for another part i will need to be able to do this.
Isnt there a way i can just call a procedure - that i would put in the controller - and that would create the html in php - and then return the whole table (that i'd create in the php).
The next question then would be, how can i do pagination.a second question - i've implemented pagination - but how can i jsut chagne the number of items on a page?
thanks very much
Bas Smit -
Re: generate tables in template

26 November 2007 at 9:42pm
you can change the amount of items per page with the 5th argument for the DataObject::get call so for pagination if you read this page - http://doc.silverstripe.com/doku.php?id=private:recipes:pagination you can see the DataObject request is
$doSet = DataObject::get(
$callerClass = "ArticlePage",
$filter = "`ParentID` = '".$this->ID."'",
$sort = "",
$join = "",
$limit = "{$_GET['start']},2"
);The last one is the value you will need to edit.
-
Re: generate tables in template

27 November 2007 at 12:12pm Last edited: 27 November 2007 12:13pm
Instead of using <% control Children %> you could implement your own method like <% control ChildrenWithLimit %> which may look something like this in your Page.php file:
Note: This goes in the Page_Controller class:
function ChildrenWithLimit() {
$start = $_GET['start'] ? (int)$_GET['start'] : 0;
$limit = "$start,5";
if($childPages = DataObject::get('Page', "ParentID = $this->ID", '', '', $limit)) {
return $childPages;
}
}Just change the 5 to how many results you want per page.
Then, you're able to use the pagination abilities as outlined at the bottom of this wiki page:
http://doc.silverstripe.com/doku.php?id=built-in-page-controls.An actual example of how pagination is implemented is the tutorial 4 - search results: http://doc.silverstripe.com/doku.php?id=tutorial:4-site-search. If you look at the Page_results.ss template in the tutorial, it has the necessary template controls.
Hope this helps,
Cheers,
Sean
| 2287 Views | ||
|
Page:
1
|
Go to Top |



