0

UPDATE: I implemented this solution to check the loading of layout which confirms that my layout is being loaded. But not my template.

UPDATE 2: I even tried installing another version of magento 2.1.11 but the issue persists whereas everything works fine in my old project (magento2.1.5) from where I've taken out the module. UPDATE 3: Weirdest thing is no any template of my previously working modules is loaded in these fresh installations.

I have developed a module which works perfectly and I copied that module in a fresh magento installation. My Vendor/Module/etc/frontend/routes.xml is:

<?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="paym" frontName="paym">
            <module name="Vendor_Module" />
        </route>
    </router>
</config>

My controller is Vendor\Module\Controller\Redirect\Index.php

<?php  
namespace Vendor\Module\Controller\Redirect;
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 $this->resultPageFactory->create();
    }
}

My app/code/Vendor/Module/view/frontend/layout/paym_redirect_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">
    <body>
        <referenceContainer name="content">
            <block class="Vendor\Module\Block\PaymentProcessor" name="custompayment" template="Vendor_Module::redirect.phtml" />
        </referenceContainer>
    </body>
</page>

My template is Vendor/Module/view/frontend/templates/redirect.phtml

<?php 
echo 'hello';
die();
?>

The issue is template does not load. When I write echo 'hi'; die(); in controller it shows up.

Another weird thing I have noticed is when I randomly delete a matching tag in paym_redirect_index.xml and run php bin/magento setup:di:compile no error occurs. But in real any small error in .xml file would never allow any magento command to execute. I even removed

     </body>
</page>

and <?xml version="1.0"?> one by one, no error occurs in command line. Also no error in logs, console. I have enabled php error reporting by writing on the top of index.php:

error_reporting(E_ALL);
ini_set('display_errors', 1);

I have renamed pub/errors/local.sample.xml to local.xml. But the thing is a blank screen loads without any error. Can anyone help me debug this issue?

4
  • Issue seems to be with your layout file name , Your layout file name should be router_controller_action.xml – Piyush Jan 29 '18 at 10:01
  • Hello @Piyush , actually this is fine, you may see that above. – Purushotam Sangroula Jan 29 '18 at 10:07
  • your module is enable? – Keyur Shah Jan 29 '18 at 10:09
  • @KeyurShah, yes I checked in CLI, backend and /app/etc/config.php as well. – Purushotam Sangroula Jan 29 '18 at 10:11
0

The block class you are calling is Vendor\Module\Block\PaymentProcessor, does this exist? If it does, it needs to extend the template class Magento\Framework\View\Element\Template to be able to render the template. Just to test this out, call the template class in your XML file like this:

<?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">
    <body>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="custompayment" template="Vendor_Module::redirect.phtml" />
        </referenceContainer>
    </body>
</page>

This should render the template onto the page. From there you should be able to create or change the block class to fix the problem for your module.

4
  • The block class exists which inherits the Magento\Framework\View\Element\Template – Purushotam Sangroula Jan 29 '18 at 19:35
  • i just copied all your code, only changing the vendor namespace and the module name. I added in the code from my answer (using the Magento block class and not a custom one) and my template file is showing up correctly. So it's not your XML code, it's not your controller code and it's not the module not being enabled. I think it's your block class, bit that code is not posted. Also, it might just be the cache, i clear that before most page loads, so it might be worth doing here. – circlesix Jan 29 '18 at 21:11
  • you are right that there is no error in my code. But It seems like some issued in magento 2. – Purushotam Sangroula Jan 30 '18 at 7:13
  • Could it be related to CACHE_TAG used in model cache? – Purushotam Sangroula Jan 30 '18 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.