Override external view files locally in your plugin
2
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 theposts
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.
There are no comments yet
Be the first one to comment