Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Overriding a core view from a plugin?

I would like to add some checkboxes below the search field in the search form, as a part of a plugin. I cannot find any events to hook into, allowing me to alter the search form, as the search form is built entirely within the view:


Now, that view can be overridden in the theme, and that works fine. However, I then have a theme view and a plugin, both of which need to be installed together to work. Is there any way the view can be put into the plugin and be made to override the core view from there?

-- Jason


  • hbfhbf wiki guy? MVP

    did you try including the over-riding php using the same structure as you would in the theme?

  • x00x00 MVP
    edited January 2013

    One way through routing

    Another way

        $View = 'search.php';
        $ThemeViewLoc = CombinePaths(array(
            PATH_THEMES, $Sender->Theme,strtolower($this->GetPluginFolder()), 'search';
            $Sender->View=$this->GetView( $View );

    grep is your friend.

  • just put search.php in you plugin's views folder.

    grep is your friend.

  • @hbf said:
    did you try including the over-riding php using the same structure as you would in the theme?

    TBH I didn't. I'll give that a go.

  • It doesn't, arguably it could.

    I think the issue is there is one theme, and many plugins.

    grep is your friend.

  • there is a typo in the above code an extra ;

    $ThemeViewLoc = CombinePaths(array(
         PATH_THEMES, $Sender->Theme,strtolower($this->GetPluginFolder()), 'search'

    grep is your friend.

  • That is perfect @x00 - thanks :-)

    Essentially in my plugin I have this event hook:

    public function SearchController_Render_Before($Sender) {
        $Sender->Form->MyCheckboxData = {data to pass to view to add to the form}
        $Sender->View = $this->GetView('dashboard/search/index.php');

    The "dashboard/search/" path is relative to the plugin's own "views" folder. This overrides the standard view for the core SearchController. The index.php view is a copy of the core applications/dashboard/views/search/index.php but with a few extra lines in it.

    The additional code you have supplied will check whether the theme has overridden this view first, and run the theme version if it is. I'll incorporate that into my plugin too and put a note in the installation instructions to warn installers about this (you could imagine several plugins and a theme wanting to take over that view as well as possibly an updated version of the core view, and the installer would need to merge them together).

    -- Jason

  • This is the final code:

        $View = 'dashboard/search/index.php';
        $ThemeView = CombinePaths(array(
            strtolower($this->GetPluginFolder(false)), $View)
        if (file_exists($ThemeView)
        ) {
            $Sender->View = $ThemeView;
        } else {
            $Sender->View = $this->GetView($View);

    So I can override the plugin-override in the theme here:


    It is a long path, but I am aiming to keep it consistent with the path of the original view in the core and with the path that you would normally use in the theme if you wanted to override the core view.

    Hopefully this is useful to someone.

    -- Jason

Sign In or Register to comment.