October CMS resources and help articles

Simple and to the point. Optimized by the community.

Override a component property from the php code section

2
by OFFLINE, last modified on August 12th, 2019

You can access all components on the current page via

$this->page->components;

this allows you to use the setProperty method on the component class to override specific properties dynamically from a page's or layout's code section.

[products]
perPage = 9

==
function onStart()
{
    // Override the previous setting of 9 products per page.
    $this->page->components['products']->setProperty('perPage', 3);
}
==

{% component 'products' %}

Discussion

1 comment

0
info17589
Post on March 18th, 2020 5:26 PM

Can the component property be set from the partial?

For example partial with code:

function onStart() { $this->controller->addComponent('\OFFLINE\Mall\Components\Products', 'products', ['sort' => 'latest', 'perPage' => 2]);

}

We use cookies to measure the performance of this website. Do you want to accept these cookies?