Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

renderWith() what control object to use???


Reply


6 Posts   2694 Views

Avatar
ccburns

Community Member, 74 Posts

14 June 2011 at 6:11pm

Edited: 14/06/2011 6:12pm

Hi Guys,

I am struggling a little with this... Obviously it is going to be a really simple answer, but I just can't crack it at the moment.

I am creating a browse page with ajax links to show more items.

So I have the AJAX working fine but my main problem is that I can get the dataobject to actually pass information through to the new template I a calling with renderWith(). I have tested and there is info in the dataobject it is just my lack of understand which value I should be using in the template I think

Function to return a list of books

public function books() {

$books = DataObject::get('Book', "ItemType = 'have' AND Status = 'available'", 'Created DESC, Value DESC', '');
return $this->renderWith('BrowsePage_Books');

}

Template = BrowsePage_Books.ss

<div id="AllBooks" class="categoryBoxes">
   <h2>Latest Books <a href="">View all Books</a></h2>
<ul id="ProductListing" class="productListing">
<% control Book %>
<li class="$FirstLast">
         <a href="" class="productImage">
<% control ItemImage1 %>
<img src="$CroppedImage(104,104).URL" alt="$Title" class="entry-image" />
<% end_control %>
</a><br/>
         <p class="productTitleContainer"><a href="" class="productTitle">$Title :: $Author</a></p>
            <a href="" class="getItemLink">Get Item</a>
</li>
<% end_control %>
   </ul>
   <div style="clear:both;"></div>
</div>

I saw this post and so I tried [url=http://www.silverstripe.org/template-questions/show/15204]http://www.silverstripe.org/template-questions/show/15204[/url]

<% control Me %>

But still no luck... Obviously I am just not in the right context, but struggling to work out which context I should be in... Any help appreciated.

Thanks,
Colin

Avatar
chillburn.com.au

Community Member, 12 Posts

14 June 2011 at 8:31pm

hey colin, u need to pass the data back to the template.

try something like:

$books = DataObject::get('Book', "ItemType = 'have' AND Status = 'available'", 'Created DESC, Value DESC', '');
$this->customize(array('books' => $books))->renderWith('BrowsePage_Books');

Avatar
SSadmin

Community Member, 90 Posts

16 June 2011 at 9:50am

@ccburns chillburn.com.au 's solution is correct.

you cannot do:

return $this->renderWith('BrowsePage_Books'); it will not passing the data back to your template.

The $this->customize(array("$key"=>$value))->renderwith('Template') would do the trick.

Avatar
ccburns

Community Member, 74 Posts

16 June 2011 at 4:57pm

Thanks guys, your spot on... Thanks

Avatar
kevinlieb

Community Member, 4 Posts

29 July 2011 at 12:21pm

I am having a similar confusion. But I can't do this:
$this->customize(array("$key"=>$value))->renderwith('Template')

because the function customize() doesn't exist. Am I missing something?

I'm trying to put together some data and pass it on to the template. It is in the page controller I am trying to call $this->customize()

Thanks

Avatar
Willr

Forum Moderator, 5513 Posts

29 July 2011 at 7:51pm

It's a customize with a s. http://api.silverstripe.org/2.3/sapphire/view/ViewableData.html#methodcustomise