Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » renderWith() what control object to use???

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2545 Views
  • ccburns
    Avatar
    Community Member
    74 Posts

    renderWith() what control object to use??? Link to this post

    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

    <% 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

  • chillburn.com.au
    Avatar
    Community Member
    12 Posts

    Re: renderWith() what control object to use??? Link to this post

    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');

  • SSadmin
    Avatar
    Community Member
    90 Posts

    Re: renderWith() what control object to use??? Link to this post

    @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.

  • ccburns
    Avatar
    Community Member
    74 Posts

    Re: renderWith() what control object to use??? Link to this post

    Thanks guys, your spot on... Thanks

  • kevinlieb
    Avatar
    Community Member
    4 Posts

    Re: renderWith() what control object to use??? Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts
    2545 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.