Magento 布局 - 内容未呈现/显示 [英] Magento layout - content is not being rendered/displayed

查看:33
本文介绍了Magento 布局 - 内容未呈现/显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了各种 Magento 教程以及一本关于布局的 Magento 书籍,但我遇到了以下问题.

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

我创建了一个自定义模块,位于 app/code/local/Company/Module/.我在 Company/Module/Block/Ablock.php 中创建了一个块 Company_Module_Block_Ablock.我已经定义了 ... <frontend><layout><updates><module><file>module.xml 在 Company/Module/etc/config.xml

I have created a custom module, located in app/code/local/Company/Module/ . I have created a block Company_Module_Block_Ablock located in Company/Module/Block/Ablock.php. I have defined <config> ... <frontend><layout><updates><module><file>module.xml in Company/Module/etc/config.xml

config.xml 也有

config.xml also has

<global>
   <blocks>
      <module>
         <class>Company_Module_Block</class>
      </module>
   </blocks>
</global>

在这个module.xml里面我有:

Inside this module.xml I have:

<layout>
    <company_module_index_index>
        <reference name="content">
            <block type="module/ablock" name="myablock" template="module/ablock.phtml" />
        </reference>
    </company_module_index_index>
</layout>

我创建了一个 Company/Module/controllers/IndexController.php 并在那里定义了一个 indexAction

I have created a Company/Module/controllers/IndexController.php and have a indexAction defined there which does

$this->loadLayout();
$this->renderLayout();

但是无论我怎么尝试,我都无法显示我的 ablock.phtml.ablock.phtml 在 app/design/frontend/company/default/template/module/ablock.phtml 中.该主题已启用,并且通常在网站上运行.

But whatever I try I'm unable to get my ablock.phtml to display. ablock.phtml is in app/design/frontend/company/default/template/module/ablock.phtml. The theme has been enabled and is generally working on the site.

我什至尝试在布局中更改 module.xml,因此它甚至不使用模板,甚至这也不显示任何内容.像这样 -

I have even tried to change module.xml inside layout so its not even using a template and even this is not displaying anything. Like this -

<reference name="content">
<block type="core/text">
    <action method="setText">
        <text>Testing</text>
    </action>
</block>
</reference>

顺便说一下,自定义主题可以正常工作,否则其他页面的内容会显示在正确的位置.

By the way the custom theme works fine otherwise, other pages have content displayed in them in the correct place.

我在 .htaccess 中有 SetEnv MAGE IS DEVELOPER MODE 1,它应该有助于显示甚至警告和内容.但是我的 systems.log 和 exceptions.log 中没有错误.(是的日志记录已打开)

I have SetEnv MAGE IS DEVELOPER MODE 1 in .htaccess which is supposed to help display even warnings and things. But my systems.log and exceptions.log have no errors in them. (Yes logging is turned on)

有人对如何解决此问题有任何建议或可以发现配置或代码中的错误吗?

Anyone have any advise on how to troubleshoot this or can spot a mistake in the configuration or code?

我的下一个选择似乎是破解核心模块代码并记录我的 module.xml 被加载和解析的位置,以查看那里发生了什么.

My next option seems to be hacking the core module code and logging where my module.xml is being loaded and parsed to see what is going on there.

谢谢.

推荐答案

调试布局更新 XML 问题的步骤:

Steps to Debug Layout Update XML issues:

  1. 您的 XML 文件(local.xmlmodule.xml)是否正在加载到系统中

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

您在布局文件中使用的句柄标签是否与为您的请求生成的句柄匹配?

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

调试第 1 步的最快方法是,在显示错误的开发人员模式下,故意在布局更新 XML 文件中引入格式不正确的错误.

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>

如果开发者模式已开启并且您已清除缓存,则加载任何具有上述内容的页面都会导致错误.这让您知道 Magento 正在尝试加载您的 XML 文件.如果页面加载没有问题,则意味着您的 XML 文件位于错误的位置,或者您在 config.xml 中错误配置了 XML.

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.

接下来是检查布局句柄.您需要确保使用的是正确的.您可以通过在您的 loadLayoutrenderLayout 请求之后调用以下来查看用于特定请求的布局句柄

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__);

我发现上述项目通常可以解决 90% 的布局问题.一定要经历几次这个过程,因为很容易错过一个步骤,并在它不正常时假设某件事是对的.冒着我通常的骗子风险,这也是我创建 Commerce Bug(商业调试)的部分原因扩展)是为了快速提供这些信息,一目了然,以帮助调试问题.

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

但是,您在 layout.xml 中定义的句柄是

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

将句柄更改为module_module_test,您应该已设置.

Change the handle to module_module_test and you should be set.

这篇关于Magento 布局 - 内容未呈现/显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆