Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

Override external view files locally in your plugin

2
by mjauvin, last modified on March 10th, 2022 - Previously published on OctoberTricks

Let's say you want to override a controller's view file (e.g. the Winter.Blog Posts controller):

  • copy the original view file into your plugin partials directory, under the posts folder.
  • modify the copied file to your liking
  • add the following code to the boot method of your Plugin registration file:
use Winter\Blog\Controllers\Posts;

public function boot()
{
    Posts::extend(function($controller) {
        list($author, $plugin) = explode('\\', strtolower(get_class()));
        $partials_path = sprintf('$/%s/%s/partials/posts', $author, $plugin);
        $controller->addViewPath($partials_path);
    });
}

You could also change any of the List widget's view files for a particular controller, adding this relationExtendViewWidget() method to one of your controller:

public function relationExtendViewWidget($widget, $field, $model)
{
    $partials_path = '$/author/plugin/partials/lists/';
    $widget->addViewPath($partials_path);
}

Just copy any of the view files under modules/backend/widgets/lists/partials to your plugins's author/plugin/partials/lists folder.

Of course, replace "author/plugin/" with your particular plugin path.

Discussion

0 comments

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