Skip to main content

Customising pages

Pages can be added in Photon by creating a controller class, defining a service and route.

The controller class is a standard Symfony controller that takes a Request and returns a Response. Generally, each page will have it's own controller and be an invokable class.

In this example the Twig template being rendered needs to be available in the current theme.

note

When creating the service, the parent service photon.controller.page can be used to simplify the definition. This will set all of the dependencies that are required by the Page base class.

Defining the controller:

<?php

namespace Spacecraft\DemoProject\Page;

use Photon\Core\Controller\Page;
use Symfony\Component\HttpFoundation\Response;

class DemoController extends Page
{
/**
* @return Response
*/
public function __invoke()
{
return $this->render('pages/demo.html.twig');
}
}

Defining the service:

spacecraft_demo_project.page.demo:
class: Spacecraft\DemoProject\Page\DemoController
parent: photon.controller.page

When adding a new page, simply define the route and specify the new controller service

demo:
path: /demo
defaults:
_controller: spacecraft_demo_project.page.demo