I put custom module in app/code/
. Layout is not loading. On my custom route is blank white page. Debug showing that handles =null. This is code
/app/code/Namespace/ModuleName/view/frontend/layout/test_index_index.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="namespace\Modulename\Block\ModuleBlock" name="form" template="namespace_ModuleName::form.phtml" />
</referenceContainer>
</body>
Namespace/Modulename/Controller/Index/Index.php
namespace Namespace\ModuleName\Controller\Index;
class Index extends \Namespace\ModuleName\Controller\Index
{
/**
*
*
*/
public function execute()
{
$this->_view->loadLayout();
$this->_view->renderLayout();
}
}
**/app/code/Namespace/ModuleName/Controller/Index.php
<?php
namespace Namespace\ModuleName\Controller;
use Magento\Framework\Exception\NotFoundException;
use Magento\Framework\App\RequestInterface;
use Magento\Store\Model\ScopeInterface;
/**
* Contact index controller
*/
abstract class Index extends \Magento\Framework\App\Action\Action
{
/**
* Recipient email config path
*/
const XML_PATH_EMAIL_RECIPIENT = 'trans_email/ident_general/email';
/**
* Recipient email config path
*/
const XML_PATH_EMAIL_RECIPIENT_2 = 'contact/email/recipient_email';
/**
* Sender email config path
*/
const XML_PATH_EMAIL_SENDER = 'contact/email/sender_email_identity';
/**
* Email template config path
*/
const XML_EMAIL_TEMPLATE = 'custom_cats_email_template';
/**
* @var \Magento\Framework\Mail\Template\TransportBuilder
*/
protected $_transportBuilder;
/**
* @var \Magento\Framework\Translate\Inline\StateInterface
*/
protected $inlineTranslation;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
parent::__construct($context);
$this->_transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
}
/**
* Dispatch request
*
* @param RequestInterface $request
* @return \Magento\Framework\App\ResponseInterface
* @throws \Magento\Framework\Exception\NotFoundException
*/
public function dispatch(RequestInterface $request)
{
return parent::dispatch($request);
}
}
/app/code/Namespace/ModuleName/view/frontend/templates/form.phtml
<h1>Hello</h1>
route.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="test" frontName="test" >
<module name="Namespace_ModuleName" />
</route>
</router>
frontend/route.xml