2985 Posts in 761 Topics by 740 members
Template Questions
SilverStripe Forums » Template Questions » special layout without a page class. is it possible?
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba
|
Page:
1
|
Go to End | |
| Author | Topic: | 2126 Views |
-
special layout without a page class. is it possible?

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.thanks for any advice on the issue.
-
Re: special layout without a page class. is it possible?

25 February 2009 at 6:35am
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.
-
Re: special layout without a page class. is it possible?

25 February 2009 at 8:47am
Can't you use renderWith in your page controller to tell sapphire which templates to use?
-
Re: special layout without a page class. is it possible?

25 February 2009 at 8:59am Last edited: 25 February 2009 8:59am
Yeah, that's true. Super ugly, though.
switch($this->URLSegment)
{
case "foo" :
return $this->renderWith(array('Bar'));
break;...
}
-
Re: special layout without a page class. is it possible?

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.
All this and more for only $39.95!
-
Re: special layout without a page class. is it possible?

28 October 2009 at 8:26pm
Hi,
i got the same issue.
My solution:
My 3 Files
mysite/code/Homepage.php
themes/<theme>/Homepage.ss <- my Layout template
themes/<theme>/Layout/Homepage.ss <- my templateclass Homepage extends Page {
}
class Homepage_Controller extends Page_Controller {
function init(){
parent::init();
$this->renderWith( array('Homepage') );
}
} -
Re: special layout without a page class. is it possible?

4 November 2009 at 5:53pm
I'm currently experimenting with a TextField for a template filename added to my base page class. You can then access the saved filename and add it to the template "suggestions" array with renderWith.
Here is my index method on my page class:
public function index() {
return $this->renderWith(array($this->CustomTemplateFileName, $this->ClassName, 'Page'));
}This allows setting a template file name in the CMS; almost useful.
-
Re: special layout without a page class. is it possible?

28 April 2010 at 10:00am Last edited: 24 May 2010 1:26am
What I found out is that you can actually create your own SSviewer that can output the Layout and Page data as ordinary. Here's an example:
function index(){
$ssv=new SSViewer("Page");
$ssv->setTemplateFile("Layout", "MyTemplateName");
return $this->renderWith($ssv);
}This will render the main Page as usual but use the Layout-file named "MyTemplateName.ss".
| 2126 Views | ||
|
Page:
1
|
Go to Top |





