25 February 2009 at 5:22am
I was wondering whether its possible to create a specialized template (layout) without having to add a matching PageXXX.php file.
In some situations you don't need a custom page type, only a custom layout, and in such case adding a Page class and a Page_Controller class seem redundant.
I feel your pain. I can't tell you how many times I've had to create empty classes for MySpecialPage and MySpecialPage_Controller.
One thing that might help is if it's just layout related, you can probably do it with CSS. I always specify a class and ID for my body tag
<body class="$ClassName" id="$URLSegment">
That way you can target pages based on their URLSegment.
Of course, if it's content-related, you're stuck creating empty classes. I created a Builder module that streamlines creating the classes and templates, so you can just do /builder/MySpecialPage and it does all the work.
You can probably find it if you do a search, or I can post it back up here if you're interested.
22 September 2009 at 10:53am
I too felt your pain and I am working on a solution!
I ran into the same issue on the last site I built and I have finally managed to decipher and affect which templates SilverStripe chooses early enough in the process to actually make a difference.
I'm still working out the kinks but when I'm finished you'll be able to define $allowed_templates on a class and then be able to choose between them in the CMS. This way you can assign templates to the classes that need them and have the rest functioning normally.
The solution also comes with a normal template choosing process that looks at the hierarchy and looks for templates that reflect that, so if you have a page of the Page class with a subpage of the MyPage class it will first look for Page_MyPage.ss before looking for MyPage.ss.