3060 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 758 Views |
-
A question of style.

4 December 2009 at 9:17am Last edited: 4 December 2009 9:18am
Hi!
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.
I.e.
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!
-
Re: A question of style.

4 December 2009 at 9:41am Last edited: 4 December 2009 9:43am
2.) definitely. That's how we typically create projects using SilverStripe.
Polymorphism is better than a lot of switch or if statements.
Sean
-
Re: A question of style.

4 December 2009 at 10:03am
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.
| 758 Views | ||
|
Page:
1
|
Go to Top |



