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.

Data Model Questions

A question of style.


4 Posts   876 Views


4 December 2009 at 9:17am (Last edited: 4 December 2009 9:18am), Community Member, 15 Posts


I'm fairly new to SilverStripe, but not to OO PHP5 or development in general. Firstly, from what I've seen so far I'm really liking SilverStripe.

I am currently using it to build a site wherein most of the pages that need to be under CMS control are pretty much identical to the base Page class. I.e. A title and a big rich text field is all that's needed.

However, the look and feel of some of these pages is radically different, hence they need different templates.

Now there seems to be two options (possibly more, but like I said, I'm new) for me to get the different templates working for these different, but similar pages.

1) I can just put a switch statement in the index action function within PageController and test something unique to each instance and then apply different templates.


Switch (UniqueThing) {
case '1':
use template A;
case 'n':
use template N;

2) Create a different sub page class for each unique page design and let that call the required template automatically. I.e. HomepagePage, ArticlePage, TermsPage etc etc.

I can see minor pro's and con's with either approach. I just wanted to ask the forum which way would be considered the 'SilverStripe way'?

Cheers in advance!


4 December 2009 at 9:41am (Last edited: 4 December 2009 9:43am), Forum Moderator, 921 Posts

2.) definitely. That's how we typically create projects using SilverStripe.

Polymorphism is better than a lot of switch or if statements.



4 December 2009 at 10:03am Community Member, 901 Posts

Yes, I second what Sean said!
Creating different classes doesn't create a lot of overhead (actually just a new entry in the ClassName enum) and you're still free to extend a given page-type later on... much cleaner and easier to extend.


4 December 2009 at 10:10am Community Member, 15 Posts

Thanks guys! Really prompt and helpful. :)