23483 Posts in 18976 Topics by 2878 members
|Go to End|
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.
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));
|Go to Top|