This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

ilan3853
ilan3853

I want to override the categoryFilter property of the blog component on page load, but nothing I do seems to work. I tried using the external parameters, but it just doesn't get passed to the property (I added var_dump( $this->property('categoryFilter')); on the blog component loadCategory() function to make sure). When I set it with the properties editor in the backend it work perfectly, but as soon as I try anything else I get NULL. I tried the following:

{% component 'blogPosts' externalParam='category-slug' %}

{% component 'blogPosts' category='category-slug' %}

{% component 'blogPosts' categoryFilter='category-slug' %}

{% set externalParam= 'category-slug' %}
{% component 'blogPosts' %}

{% set category= 'category-slug' %}
{% component 'blogPosts' %}

{% set categoryFilter= 'category-slug' %}
{% component 'blogPosts' %}

And any combination of the following both on the onStart() and onInit() functions in the code block:

function onInit() {
    $this['category'] = "category-slug";
    $this['categoryFilter'] = "category-slug";
    $this['externalParam'] = "category-slug";
    $this->page['category'] = "category-slug";
    $this->page['categoryFilter'] = "category-slug";
    $this->page['externalParam'] = "category-slug";
    $this->blogPosts->category = "category-slug";
    $this->blogPosts->categoryFilter = "category-slug";
    $this->blogPosts->externalParam= "category-slug";
    $this['blogPosts']->category = "category-slug";
    $this['blogPosts']->categoryFilter = "category-slug";
    $this['blogPosts']->externalParam = "category-slug";
}

I am definitely doing something wrong, can someone help me?

Last updated

kdoon80
kdoon80

Property reading after overwriting it won't work with onInit(), It will be available later... I think you have to use onRender()

Last updated

courtney19563
courtney19563

I know this is late, but this just helped me with a similar issue. onInit() wasn't doing anything but onRender() solved the problem.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.