rainlab/blog-plugin

Category not found

Closed this issue · 3 comments

I have under my theme pages/blog/category.htm the following (as per docs):
(blog list + post pages are working fine)

title = "Category"
url = "/blog/category/:slug/:page?"
layout = "default"

[blogPosts]
categoryFilter = ":slug"
==
function onEnd()
{
    // Optional - set the page title to the category name
    if ($this->category) {
        $this->page->title = $this->category->name;
    }
}
==
{% if not category %}
    <h2>Category not found</h2>
{% else %}
    <h2>{{ category.name }}</h2>

    {% component 'blogPosts' %}
{% endif %}

I have two published posts, each with a category assigned.

But on the blog/category/{category} page, I am getting 'No category' found.

Any help much appreciated,
G

On latest ocms 2 version and blog (1.7.0):
image

Here is the code that loads the category:

protected function loadCategory()
{
if (!$slug = $this->property('categoryFilter')) {
return null;
}
$category = new BlogCategory;
$category = $category->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')
? $category->transWhere('slug', $slug)
: $category->where('slug', $slug);
$category = $category->first();
return $category ?: null;
}

In this case, you need to tweak the page settings to use an external parameter. It looks like this:

[blogPosts]
categoryFilter = "{{ :slug }}"

I hope this helps!

Works now, thanks! (I think the docs need updating though: https://octobercms.com/plugin/rainlab-blog > Documentation)

Thanks! Updated the docs too