21287 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 329 Views |
-
Rendering with default template?

15 February 2012 at 6:43am Last edited: 15 February 2012 6:43am
Hi.
How do I render a page on demand with its default template?
My code is:public function onAfterWrite() {
parent::onAfterWrite();
$render = $this->renderWith(array($this->ClassName,'Page')));
}Saving the page gives me the following error:
500//ERROR [User Warning]: None of these templates can be found in theme '': MainPage.ss, Page.ss IN POST /admin/EditForm Line 207 in /var/www/vhosts/orange.czterystacztery.pl/htdocs/sapphire/core/SSViewer.php
As you can see, current theme name variable is surprisingly empty, although I use set_current_theme() in config.php
All I need to do is export my page into a static file. But I am unable to get its published content.
What am I doing wrong?
Is there any method to render a page with its default template? Like $this->render() and not $this->renderWith() -
Re: Rendering with default template?

15 February 2012 at 6:53am
For the future me:
I just found Director::test($this->Link())->getBody() but I don't consider it a kosher way to do this.
-
Re: Rendering with default template?

16 February 2012 at 12:36am Last edited: 16 February 2012 12:38am
I don't think you can render a page from within the Page class: OnAfterWrite() belongs to the DataObject (the Page). It's the Page_Controller that knows howto render itself...
So you should be able to do it like this (haven't tested it though):
$class = $this->ClassName . "_Controller";
$controller = new $class($this);
$render = $controller->renderWith(array($this->ClassName,'Page')));Having said that, I think OnAfterWrite() might be called multiple times. So it might not be a good idea to do this - unless you at least cache $render.
As for Director::test - I think SilverStripe uses it in their Static caching - so you might as well, as long as it works - although normally 'test' would make me hesitate as well
| 329 Views | ||
|
Page:
1
|
Go to Top |

