Jump to:

23374 Posts in 18175 Topics by 2866 members

General Questions

SilverStripe Forums » General Questions » Customise() on a dataobject

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1553 Views
  • micahsheets
    Avatar
    Community Member
    164 Posts

    Customise() on a dataobject Link to this post

    I have a page where I am combining the Content from a few child pages by getting a dataobjectset of the pages and then using a foreach loop to concatenate the Content data. To format the Content area I call renderWith() on each page using a custom template for just the content and add that to the Content of the Actual page I am on. I have some logic I want to run to change add some stuff to each page content before it is rendered so I tried

    $child->customise(array('foo' => $bar))->renderwith('customtemplate');

    Where $child is the Page dataobject. However this doesn't work and I suspect it is because customise() is usually called from within a page's controller and refers to $this.

    So the basic question is can a dataobject be customised and then rendered with a template? Seems like I have done this before but not in SS 2.4.5.

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: Customise() on a dataobject Link to this post

    That code you have is correct. It will render the $child object with the main customtemplate.ss template, and returns the output (not output it to the browser).

    You can also pass the array to the renderWith call instead of first customising:

    $renderedContent = $child->renderWith('customtemplate', array('foo' => $bar));

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