I'm adding a new page for my company, and that requires the use of a module. After some searching, I got the routes to function. However, the page doesn't seem to load the block/template as defined in my module_controller_action.xml file.
Module structure for as far as relevant:
-+ MyCompany
-+ CustomRouter
-+ Controller
-+ Test
- Test.php (Gets called as expected)
- Router.php
-- etc/...
-+ view
-+ frontend
-+ layout
- customrouter_test_test.xml
-+ templates
- configure_price_list.phtml
I'm using a block from Magento/Customer/Blocks/Account/Dashboard/Info. This block already has all that I need. I tried using an exact copy, but didn't notice any change.
My files: Test.php:
<?php
namespace MyCompany\CustomRouter\Controller\Test;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
class Test extends \Magento\Framework\App\Action\Action
{
protected $resultPageFactory;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute()
{ // This function gets called 100% when expected, so the problem isn't in the router
$this->_view->loadLayout();
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->set(__('Configure Price List'));
return $resultPage;
}
}
customrouter_test_test.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" layout="1column">
<body>
<referenceContainer name="content">
<block class="Magento\Customer\Block\Account\Dashboard\Info" name="configure_price_list" template="configure_price_list.phtml" cacheable="false" />
</referenceContainer>
</body>
</page>
configure_price_list.phtml:
<?php
// Made by (my name)
?>
<div class=configure-price-list>
<p>Template Loaded</p>
</div>
The page loads, and the page title gets displayed as I set it in Test.php. However, none of the content displays, as if customrouter_test_test.xml does not exist. Is there anyone who can point me to the missing link here ?
(Did try to watch a number of tutorials, according to them, current setup should work.)
EDIT: After request, here's routes.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
<router id="standard">
<route id="customrouter" frontName="customrouter">
<module name="MyCompany_CustomRouter" />
</route>
</router>
</config>
And at the risk of stating the obvious, I'm loading [domain]/customrouter/test/test. I'm also loading another url I redirected with a custom router, which looks exactly the same (just the page heading I set in Test.php).
EDIT 2: I might have found a solution. But I'm still working on what caused the problem. currently im file-for-file switching a working custom action to act exactly like mine.
static:content:deploy
andcache:flush
commands? Also add$this->_view->loadLayout();
this line in your controller's execute method.router.xml
file look like? The one frometc/frontend