【问题标题】:Magento block reference orderMagento 区块参考顺序
【发布时间】:2016-02-08 15:50:18
【问题描述】:

我在 Magento 上创建了一个自定义扩展来在主要内容上呈现一个块。但是如何选择要显示的订单呢?现在正在内容下方显示。 有没有办法在块之后或之前定义?如何查看要在之前或之后渲染的块的名称?

    app/code/local/SpaceName/Infrontpage/Block/Infrontpage.php
    <?php 
 class Rand_Infrontpage_Block_Infrontpage extends Mage_Core_Block_Template{

    function getcustombanner() {


        return 'FERNANDAO CUSTOM BLOCK';

        }
 }

?>

那么我有:

app/code/local/SpaceName/Infrontpage/etc/config.xm<?xml version="1.0"?>
<config>
    <modules>
         <Rand_Infrontpage>
            <version>0.1.0</version>
        </Rand_Infrontpage>
    </modules>
    <global>   
        <blocks>
            <infrontpage>
                <class>Rand_Infrontpage_Block</class>
            </infrontpage>
        </blocks>
    </global>
    <frontend>
        <layout>
            <updates>
                <infrontpage>
                    <file>infrontpage.xml</file>
                </infrontpage>
            </updates>
        </layout>
    </frontend>
</config>

和:

app/design/frontend/base/default/layout/infopage.xml
<?xml version="1.0"?>

<layout version="0.1.0">

    <cms_index_index>
        <reference name="content">
             <block type="infrontpage/infrontpage" name="infrontpage" template="infrontpage/infrontpage.phtml" />
        </reference>

    </cms_index_index>
</layout>

最后:

app/design/frontend/base/default/template/infrontpage/infrontpage.phtml\
<h1 class="infrontpage" style="text-align: center;"><?php echo $this->getcustombanner(); ?></h1>

【问题讨论】:

    标签: magento reference block


    【解决方案1】:

    在 Magento 中,before="child.block.name"after="child.block.name" 属性用于定义块的顺序。如果没有指定这些属性,那么这些块将按照 Magento 读取它们的顺序呈现。

    例如

    <reference name="root">
       <block type="core/template" name="example_block" before="content" template="page/html/example-block.phtml"/>
    </reference>
    

    【讨论】:

    • 酷,谢谢。如何获取块的名称以便在它之前创建一个钩子?
    猜你喜欢
    • 2016-12-04
    • 1970-01-01
    • 2012-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 2012-09-29
    • 1970-01-01
    相关资源
    最近更新 更多