The objective of this is to build a simple route, and controller that handles this entire “application.”

The components of this simple prototype are essentially a bunch of HTML pages with interaction hard-coded or baked into the twig templates. So the objective here is to build the structure such that building a new template is all that is required and the application will then pick it up.


  1. Separately a custom controller handles exception catching and 404 errors.
  2. Everything, including authentication/authorization can be “faked”
    1. Presumably you’d hide this behind HTTP-Basic or keep local only.

The Route

    path:      /{section}/{page}
    defaults:  { _controller: DemoBundle:Default:index }
        section: [a-zA-Z0-9\-]
        page: [a-zA-Z0-9\-]

The Controller

 * The default Action for the Demo app
 * @param string $section Alphanumeric string representing the template dir
 * @param string $page Alphanumeric string representing the template file
public function indexAction(Request $request, $section, $page)
    $template = sprintf('DemoBundle:%s:%s.html.twig', ucfirst($section), $page);
    //@TODO: verify $template is valid before sending to $render
    return $this->render($template);

How it Works

Now all you need to do is build your filenames to match and you can create template files that work out of the box.

Now your routes map to filenames, which for the purposes of a simple static HTML prototype makes things very easy for any designer or developer to add and work with:

Route (path) Template filename
/jake/home DemoBundle\Resources\views\Jake\home.html.twig
/auth/forgot-password DemoBundle\Resources\views\Auth\forgot-password.html.twig
/jake/dashboard DemoBundle\Resources\views\Jake\dashboard.html.twig