O'Reilly logo

Magento 2 - Build World-Class online stores by Jonathan Bownds, Bret Williams, Vladimir Kerkhoff, Ray Bogman, Fernando J. Miguel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a web route and controller to display data

In order to display data from your extension on the frontend (the public part of the website), the following is necessary:

  • A configured route
  • A controller handling the request
  • A layout file to specify what to show
  • The block class as specified in the layout file
  • A template file (optional)

How to do it…

Follow these steps to extend your module with a frontend web route and output data from a template file:

  1. Create a route in the frontend area:

    etc/frontend/routes.xml

    <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> <router id="standard"> <route id="sample" frontName="sample"> <module name="Genmato_Sample" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required