Controllers for Page Types

Like single pages, page types can also employ controllers. The view() method for a page type's controller will automatically be run any time a page of that type is browsed to in the site. This controller can send data from that page type into the view.

Check the Page Type

First, make sure you know your desired page type's handle. Let's say we want to add a controller to the "Blog Entry" page type in the Elemental Theme, which has a handle of blog_entry.

Create the controller file

Create a controller file at application/controllers/page_types/blog_entry.php.

Create the controller class within the file

The controller class should have the StudlyCapsed version of your page type handle, within the Application\Controller\PageType namespace.

namespace Application\Controller\PageType;

use Concrete\Core\Page\Controller\PageTypeController;

class BlogEntry extends PageTypeController

    public function view()

Controller Note

In this example, the page type controller extends the PageTypeController class within the \Concrete\Core\Page\Controller namespace, rather than the PageController. This is not strictly necessary, as currently the PageTypeController class is an empty class that just extends PageController – but in the future there might be important methods that we place within PageTypeController, so it's smart to extend that class just the same.

That's It

That's all you have to do. Any view() method within the page type controller will automatically be fired, and any data it sets will be available in the page's template.