This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I have a simple website that incorporates the RainLab Blog plugin. I have some code to change the page title so that it matches the blog title as well as setting the header image to be the featured image of the blog. That code is here:
function onEnd() {
$this->page->title = $this['post']->title;
$this['header'] = $this['post']->title;
$this['background'] = $this['post']->featured_images[0]->path;
}
The code works fine and displays everything correctly, the problem is when I try to navigate back to another page I get this error:
Undefined property: Illuminate\Http\Response::$title /Applications/MAMP/htdocs/OctoberCMS/install-master/themes/bayramoff-theme-cleanblog/pages/blog-post.htm line 14 TYPE
PHP Content
EXCEPTION
Cms\Classes\CmsException
8 9 10 11 12 13 14 15 16 17 18 19 20 slug = "{{ :slug }}" categoryPage = "blog"
<?php
function onEnd()
{
$this->page->title = $this['post']->title;
$this['header'] = $this['post']->title;
$this['background'] = $this['post']->featured_images[0]->path;
}
?>
Does anyone have any idea what this error is? Sorry for my ignorance but I'm new to October and Laravel both so I'm sure this is something simple but I'm at a loss. Thanks in advance for any help.
The root issue is a bug in the Blog plugin, it will set $this['post']
to a Response object meant to return a 404 if the requested post isn't found when the component is run; since your code assumes that variable to always be an existing instance of a Post model it fails. I've submitted a PR to the blog plugin to fix the issue, please take a look and try it out so you can let us know if that fixed it for you: https://github.com/rainlab/blog-plugin/pull/512/files
Luke, Thanks for your response. I copied the code you provided and put it in the components/Post.php file, however, when I run it now I get this error:
Parse error: syntax error, unexpected 'public' (T_PUBLIC) /Applications/MAMP/htdocs/OctoberCMS/install-master/plugins/rainlab/blog/components/Post.php line 123 TYPE
Undefined
EXCEPTION
Symfony\Component\Debug\Exception\FatalThrowableError
117 118 119 120 121 122 123 124 125 126 127 128 129 $post->categories->each(function($category) { $category->setUrl($this->categoryPage, $this->controller); }); } return $post; } public function previousPost() { return $this->getPostSibling(-1); } public function nextPost() { return $this->getPostSibling(1);
1-3 of 3