How to override a component property via PHP in October CMS – <yanmet.com>

How to override a component property via PHP in October CMS

To get the needed component, you can use:

$this->page->components[ 'ComponentName' ];

// Or just
$this->ComponentName;

It allows you to use method setProperty().

In this example we change collection property recordsPerPage after component init:

[collection BlogPosts]
handle = "Blog\Post"
recordsPerPage = 5
==
<?php
    function onStart () {
        // Override posts per page property from 5 to 10
        $this->page->components[ 'BlogPosts' ]->setProperty( 'recordsPerPage', 10 );
    }
?>
==
{% for Post in BlogPosts %}
    {{ Post.title }}
{% endfor %}

If you init component from partial, you can use this method to get component and change property:

$this->controller->findComponentByName( 'BlogPosts' )->setProperty( 'recordsPerPage', 10 );