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.

General Questions /

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

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

Customise() on a dataobject

Go to End

2 Posts   2327 Views


Community Member, 165 Posts

14 April 2011 at 5:37am

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.


Community Member, 473 Posts

14 April 2011 at 8:23am

That code you have is correct. It will render the $child object with the main 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));