Override default class function ComponentPartial.php?

Hi there,

Let me just start explaining what we are trying to achieve. We have 1 master ‘theme’ this theme will get a ‘child theme’ on en new customers installation. All the partials and theming for plugins and modules will be done in this chil themes directory. The default way to override these themes can be done in a more easier en in our opinion more logical way. We want to change the function ‘loadOverrideCached’ located in \modules\cms\ComponentPartial.php so it always first looks in for: {theme directory}/partials/plugins/{vendor name}/{plugin name}/filename . it will be something llike this: /child-theme/partials/plugins/rainlab/blog/default.htm. (we have this working btw. )
This way we dont need any extra information present in the place where we load in the partial. Also we standardise everything like this. just as october this does for plugins and themes.

The easiest way is just to edit the ComponentPartial.php file. But then on an October update this file might be reset/overwritten. This is not something we wanna keep track of. Thus we come at the point why i am here asking for help/thoughts.

Like you can extand the AuthManager.php true a extend function

App::extend('backend.auth', function () {
            return AuthManager::instance();
        });

We would also like to extend ComponentPartial.php in the same way. Or some other way that will make this work.

Documentation on this subject is very mild or non existing. Or we are looking in the wrong place :wink:

Hi @gldrenthe89

Thanks for this question. We’ve been thinking about simplifying this recently. It’s documented here:

Overriding a component’s partial has a very limited subset of uses. In most cases, converting a component’s partial to a CMS partial is much easier. There is little difference in doing it this way.

As an example, a blog component rendered like this…

[blog]
==
{% component 'blog' %}

Is primarily the same as

[blog]
==
{% partial 'blog::default' %}

So if you copy the default.htm partial to your theme as blog-default.htm, you can render it the same way.:

[blog]
==
{% partial 'blog-default' %}

In this way, overriding component partials is discouraged since using CMS partials is much simpler.

Thanks, you openend some eyes at our end. we will try it that way.

1 Like

Thanks @gldrenthe89! We’ll be sure to add this advice to the documentation to help others as well.