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, biapar, Willr, Ingo, swaiba, simon_w

Customise() on a dataobject


Reply


2 Posts   1750 Views

Avatar
micahsheets

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.

Avatar
simon_w

Forum Moderator, 474 Posts

14 April 2011 at 8:23am

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