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:
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" /> </route> </router> </config>
Create the controller that handles the request and renders the output:
Controller/Index/Index.php
<?php namespace Genmato\Sample\Controller\Index...