如何在布局文件中设置自定义块?

时间:2014-04-09 14:29:14

标签: xml magento layout

我无法在advancedSearch.xml布局中设置块。我的扩展程序名称为 Rockstar_Chatattributes 。 这是我的config.xml(只是必要的节点):

<?xml version="1.0"?>
<config>
<modules>
    <Rockstar_Chatattributes>
        <version>1.0.0</version>
    </Rockstar_Chatattributes>
</modules>
<global>
    <blocks>
        <chatattributes>
            <class>Rockstar_Chatattributes_Block</class>
        </chatattributes>
    </blocks>
</global>
<frontend>
    <routers>
        <chatattributes>
            <use>standard</use>
            <args>
                <module>Rockstar_Chatattributes</module>
                <frontName>advancedSearch</frontName>
            </args>
        </chatattributes>
    </routers>
    <layout>
        <updates>
            <chatattributes>
                <file>advancedSearch.xml</file>
            </chatattributes>
        </updates>
    </layout>
</frontend>

这是advancedSearch.xml:

<layout version="0.1.0">
<chatattributes_index_index>
<reference name="content">
<block type="chatattributes/john" name="john" as="john" template="chatattributes/john/view.phtml" />
</reference>
</chatattributes_index_index>

这里/app/design/frontend/default/mytemplate/template/chatattributes/john/view.phtml正在查找我的模板

这是我的块(app / code / local / Rockstar / Chatattributes / Block / John.php):     

class Rockstar_Chatattributes_Block_John extends Mage_Core_Block_Template
{
public function logic() {
    echo 'block has been included';
}
}

所以现在我的块只是忽略了。 但是当我在advancedSearch.xml中键入core / template而不是chatattributes / john时,模板中的文本显示正常。

1 个答案:

答案 0 :(得分:0)

检查布局版本的值。它位于0.1.0 advancedSearch.xmlconfig.xml's version1.0.0。我想这可能是错误的。这两个文件的版本必须相同。在任何一个文件中更改这些值。