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   2599 Views

Avatar
ccburns

14 June 2011 at 6:11pm (Last edited: 14 June 2011 6:12pm), Community Member, 74 Posts

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

14 June 2011 at 8:31pm Community Member, 12 Posts

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

16 June 2011 at 9:50am Community Member, 90 Posts

@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

16 June 2011 at 4:57pm Community Member, 74 Posts

Thanks guys, your spot on... Thanks

Avatar
kevinlieb

29 July 2011 at 12:21pm Community Member, 4 Posts

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

29 July 2011 at 7:51pm Forum Moderator, 5511 Posts

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