I have a simple module Alpine_AlpineCustom but it seems that my layout.xml file is not being applied properly and I just can't see why.
I can see via Commercebug that the layout file alpinecustom_index_index.xml
is seen, but when I call my page it I see a "1column" page with "Create New Customer Account" and not my content. So either my layout is either not working, working wrong, or is ignored for this path block.
My router, controller, template seem to work properly because if I put $block->setTemplate('Alpine_AlpineCustom::alpine.phtml');
in my execute function things show as expected without error.
It must be something simple and obvious between the block and the layout, a path or name mismatch but I just cannot see it. It is the right block name and template reference since they work elsewhere.
What am I not seeing?
Bonus question: why is it showing "Create New Customer Account"?
Alpine\AlpineCustom\view\frontend\layout\alpinecustom_index_index.xml:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>Layout Alive</title>
</head>
<body>
<referenceContainer name="content">
<block class="Alpine\AlpineCustom\Block\Index" name="alpinecatalog" template="Alpine_AlpineCustom::alpine.phtml" />
</referenceContainer>
</body>
</page>
Alpine\AlpineCustom\Block\Index.php
<?php
namespace Alpine\AlpineCustom\Block;
class Index extends \Magento\Framework\View\Element\Template
{
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
array $data = []
)
{
parent::__construct($context, $data);
}
protected function _prepareLayout()
{
return parent::_prepareLayout();
}
public function getAlive()
{
return 'Module Index Block ALIVE';
}
}
?>
Alpine\AlpineCustom\Controller\Index\Index.php
<?php
namespace Alpine\AlpineCustom\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory 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()
{
$this->_view->loadLayout();
$this->_view->getLayout()->initMessages();
//$block = $this->_view->getLayout()->createBlock('Alpine\AlpineCustom\Block\Index');
//$block->setTemplate('Alpine_AlpineCustom::alpine.phtml');
//$this->getResponse()->appendBody($block->toHtml());
/** @var \Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
return $resultPage;
}
}
?>
Alpine\AlpineCustom\etc\frontend\routes.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="alpinecatalog" frontName="alpinecatalog">
<module name="Alpine_AlpineCustom" />
</route>
</router>
</config>