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

Showing multiple formatted page types on a single page

Go to End

3 Posts   770 Views


Community Member, 136 Posts

2 September 2011 at 3:52pm

Howdy Everyone

I've got a scenario where I want to show multiple formatted pages on a single page. For example I might have 4 different page types:


The templates attached to each of these output HTML without <html><head><body> tags. Each page could be viewed independently but I also want to be able to join them into one long page and retain any formating or interactive elements.

Is there a relatively easy way of going about this?

Pages can be referenced via the "ID" and "Classname" fields. What would be the correct way of calling an ID so the HTML is returned using the templates defined by "Classname"?

I hope this makes sense, thank you in advance.



Community Member, 473 Posts

2 September 2011 at 7:54pm

Every subclass of ViewableData (DataObject extends this, and SiteTree extends DataObject, then your Pages extends from SiteTree) have a forTemplate() method, which renders the object in its default manner.

There is also renderWith(), which takes either a single template name or a list of template names, that works similar to forTemplate(), but uses the specified template.

There's the static method DataObject::get_by_id($class, $id), that returns the object of $class with the ID $id.

So you could do things like:

$ids = array(…);
$content = '';
foreach($ids as $id) {
$content .= DataObject::get_by_id('Page', $id)->forTemplate();
return $content;

Here I'm assuming all your page types extend from Page.


Community Member, 136 Posts

5 September 2011 at 1:46pm

Hi Simon

Thank you for that, it's got me going in the right direction.

I used your code as a base and got the following error:

[User Error] Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'Page'

Any ideas?

I'm going to have a look at "renderWith()" to see if that might suit what I'm trying to achieve.