I've got a silverstripe blog which I'm using for a couple different areas in the site and want to use a different template for each (rather than trying to use lots of conditions in the template)..I can't get the template to render - heres the bare bones:
class BlogExtension extends DataExtension
{
private static $db = [
'BlogType' => 'Varchar'
];
}
class BlogPostExtension extends DataExtension
{
public function isNews()
{
return $this->owner->Parent()->BlogType == 'news';
}
public function isBlog()
{
return $this->owner->Parent()->BlogType == 'blog';
}
}
And, I'm tring to do something like the following to render each blogpost type in either BlogPost_news.ss or BlogPost_blog.ss:
class BlogPostControllerExtension extends DataExtension
{
public function onBeforeInit() {
//render with custom template
if ($this->owner->isBlog()) {
return $this->owner->renderWith(BlogPost::class .'_blog');
}
}
But I don't think I'm quite on the right track here :)