Magento layout - content is not being rendered/displayed

前端 未结 4 811
独厮守ぢ
独厮守ぢ 2020-12-28 23:43

I have gone through various Magento tutorials as well as a Magento book on layout, but I\'m stuck with the following problem.

I have created a custom module, located

相关标签:
4条回答
  • 2020-12-28 23:51
    • did you disable or update Magento cache?
    • is your module enabled? Is it listed in System, Configuration, Advanced, Advanced?
    • which class does your Block extend?

    Regards, Alessandro

    0 讨论(0)
  • 2020-12-29 00:06

    Steps to Debug Layout Update XML issues:

    1. Is your XML file (local.xml or module.xml) being loaded into the system

    2. Does the handle tag you used in your layout file match a handle being generated for your request?

    The quickest way to debug step 1 is, while in developer mode with errors showing, deliberately introduce a non-well-formed error to your Layout Update XML file.

    <layout <!-- notice missing closing taglayout -->
        <company_module_index_index>
            <reference name="content">
                <block type="module/ablock" name="myablock" template="module/ablock.phtml" />
            </reference>
        </company_module_index_index>
    </layout>
    

    If developer mode is on and you've cleared your cache, loading any page with the above in place will cause an error. This lets you know that Magento is trying to load your XML file. If the page loads without problem, that means you have your XML file in the wrong location, or you've misconfigured your XML in config.xml.

    Next up is your checking your layout handle. You'll want to make sure you're using the right one. You can view the layout handles that were used for a particular request by calling the following after your loadLayout and renderLayout request

    //from a controller action
    $this->loadLayout();
    $this->renderLayout();
    var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
    exit("bailing early at ".__LINE__." in ".__FILE__);
    

    I've found the above items usually take care of 90% of layout problems. Be sure to go through the process a few times, as it's easy to miss one step and assume something's all right when it's not. Taking my usual risk of being a shill, part of why I created Commerce Bug (commercial debugging extension) was to provide this information quickly, and at a glance, to help with debugging problems.

    Based on your comments below, the problem appears to be the layout handle you're using. The handle that's generated by the system is

    module_module_test
    

    However, the handle you're defining in your layout.xml is

    company_module_index_index
    

    This is the "full action name" handle. The typical syntax for this is

    frontname_controllername_actionname
    

    Change the handle to module_module_test and you should be set.

    0 讨论(0)
  • 2020-12-29 00:06

    In magento 2.3.2, you have to enter this code for getting layout handle

    echo $this->getRequest()->getFullActionName();
    

    So the controller execute function like this

        public function execute()
        {
    
            echo $this->getRequest()->getFullActionName();exit;
        }
    

    And check the value printed on screen if it is same with layout handle name

    0 讨论(0)
  • 2020-12-29 00:10

    I cannot tell without seeing all of your config.xml, you might be missing a section like this:

    <frontend>
        <routers>
            <company_module>
                <args>
                    <frontName>module</frontName>
                    <module>Company_Module</module>
                </args>
                <use>standard</use>
            </company_module>
        </routers>
    </frontend>
    

    Then, to reach the indexAction or your indexController you would need the address www.example.com/module. That will mean the layout handle company_module_index_index is used when you load the layout. BTW, the posted layout XML is broken, the closing tag does not match the opening tag.

    0 讨论(0)
提交回复
热议问题