Use theme layout from Plugin Controller

Hi there,

I’m using October v3 and have created a plugin. I can create and tinker with Controller actions and create custom views. When these are for the backend the views correctly use the backend/admin layout template.

If I create a controller, action and view to use the default frontend theme/layout I cannot get this to work. I can render the view with all the data and markup, but no surrounding template.

I have tried a bunch of things (see below) but I cannot seem to get the default cms theme showing in my custom view.

//return view(“index”, compact(‘event’));
//$view = View::make(‘’, [‘event’ => $event]);
//new Controller->render($view);
//return View::make(‘’, [‘event’ => $event]);

            $cmsController = new \Cms\Classes\Controller;
            return $cmsController->render('test3', ['event' => $event]);

Thanks in advance if anyone can help!

Hi @jamie,

For frontend controllers, we call these “handlers”, but sometimes you will find them in a directory called “http”. Here is an example: october/Installer.php at develop · octobercms/october · GitHub

And the corresponding views: october/modules/system/views at develop · octobercms/october · GitHub

This all assumes you don’t wish to use the theme, which has its routing and view system.

Finally, you’ll need to create a routes.php file to assign a URL to the controller/handler: october/routes.php at develop · octobercms/october · GitHub