I have doubt as how to create Frontend Module with View template files. I have created Module using this reference Magento Documentation "https://devdocs.magento.com/videos/fundamentals/create-a-new-page/". In this Documentation they have Completed till the Controller section, they haven't explained as how to pass the collected data to view->frontend folder.
Please find the below code for creating frontend module
File path:app/code/VendorName/ModuleName/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="salesperson" frontName="salesperson">
<module name="VendorName_ModuleName"/>
</route>
</router>
</config>
File path:app/code/VendorName/ModuleName/Controller/Login/Index.php
<?php
namespace VendorName\ModuleName\Controller\Login;
class Index extends \Magento\Framework\App\Action\Action
{
protected $resultPageFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory)
{
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute()
{
return $resultPage = $this->resultPageFactory->create();
}
}
File path:app/code/VendorName/ModuleName/view/frontend/layout/salesperson_login_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" name="app_login_page" template="VendorName_ModuleName::salesperson_login_index.phtml" />
</referenceContainer>
</page>
File path:app/code/VendorName/ModuleName/view/frontend/templates/salesperson_login_index.phtml
<h1>Template file for Frontend Module</h1>
After creating all the above steps, I called the URL as http://domainname.com/salesperson/login/index , It just bring the store default header and footer content without our template code.
Someone help me as to Create View files and pass the data from controller to view files in Magento Custom Frontend Module!!!
Thanks in Advance :)
Regards, Hari