StorefrontController
class. A controller is also just a service which can be registered via the service container. Furthermore, we have to define our RouteScope
via annotation, it is used to define which domain a route is part of and needs to be set for every route. In our case the scope is storefront
.ExampleController.php
in the directory <plugin root>/src/Storefront/Controller/
.Route
annotation which has to contain our route, in this case it will be /example
. The route defines how our new method will be accessible.example.html.twig
template file with a template variable example
.Route
annotation, that points to the route /example
. Also note its name, which is also quite important. Make sure to use prefixes frontend
, api
or store-api
here, depending on what your route does. Inside the method, we're using the method renderStorefront
to render a twig template file in addition with the template variable example
, which contains Hello world
. This template variable will be usable in the rendered template file. The method renderStorefront
then returns a Response
, as every routed controller method has to.RouteScope
per route.call
tag, which is necessary in order to set the DI container to the controller.routes.xml
file at <plugin root>/src/Resources/config/
location. Have a look at the official Symfony documentation about routes and how they are registered.index.html.twig
file. Thus we have to create an index.html.twig
in the <plugin root>/src/Resources/views/storefront/page/example
directory, as defined in our controller. Below you can find an example, where we extend from the template base.html.twig
and override the block base_content
. In our Customize templates guide, you can learn more about customizing templates.Request
and SalesChannelContext
instances in our controller method.