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

查看:136
本文介绍了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位于Company / Module / Block / Ablock.php。我已定义< config> ...< frontend>< layout>< update>< module>< file> module.xml in / 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.

我有 SetEnv MAGE是开发者模式1 在.htaccess中,它应该帮助显示甚至警告和事。但我的systems.log和exceptions.log中没有错误。 (Yes logging is turned on)

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.xml .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.

接下来是检查你的布局句柄。你要确保你使用正确的。您可以通过调用之后您的 loadLayout renderLayout 来查看用于特定请求的布局句柄。 code> request

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天全站免登陆