Magento复制自定义块

时间:2009-09-28 13:53:42

标签: magento

我对任何Magento开发人员都有一个问题,我无法解决。 我已经在类别模板中创建了一个自定义模块和块。这是我的文件设置

1。应用程序/代码/本地/ Tsb.Category的/ etc / config.xml中

<?xml version="1.0"?>
<config>
    <modules>
        <Tsb_Category>
            <active>true</active>
            <codePool>local</codePool>
        </Tsb_Category>
    </modules>
</config>

2。应用程序的/ etc /模块/ Tsb_Category.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Tsb_Category>
            <active>true</active>
            <codePool>local</codePool>
        </Tsb_Category>
    </modules>
</config>

3。应用程序/代码/本地/ TSB /类别/块/ view.php

class Tsb_Category_Block_View extends Mage_Core_Block_Template
{
    private $message;
    private $att;

    protected function createMessage($msg) 
    {
        $this->message = $msg;
    }

    public function receiveMessage() 
    {
        if($this->message != '') 
        {
            return $this->message;
        } else {
            $this->createMessage('Hello World');
            return $this->message;
        }
    }

    protected function _toHtml() 
    {
        $html = parent::_toHtml();
        /*echo "MY CUSTOM ATTR IS" . $this->getData('my_custom');
        echo "MY CUSTOM ATTR IS" . $this->getMyCustom(); */

        if($this->att = $this->getData('my_custom') && $this->getData('my_custom') != '') 
        {
            $html .= '<br />'.$this->att;
        } else {
            $html .= '<br />No Custom Attribute Found';
        }

        return $html;
    }
}

4。应用程序/设计/前端/ TSB /默认/模板/类别/ view.phtml

<div>
    <span><strong>This is the output of the fido example:</strong></span><br />
    <span style="color:#FF9933;">
    <?php echo $this->receiveMessage() ?>
    </span>
</div>

5。应用程序/设计/ frontendtsb /默认/布局/的catalog.xml

<!--
Category default layout
-->

<catalog_category_default>
    <reference name="left">
        <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
    </reference>
    <reference name="content">
        <!-- POSSIBLY CTAS FOR MAIN PRODUCT / TOP SELLER -->
        <block type="tsb_category/view" my_custom="Test" template="category/view.phtml" before="category.products" />
        <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
            <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
                <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">

                    <!-- The following code shows how to set your own pager increments -->
                    <!--
                        <action method="setDefaultListPerPage"><limit>4</limit></action>
                        <action method="setDefaultGridPerPage"><limit>9</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>2</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>4</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>6</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>8</limit></action>
                        <action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
                    -->
                </block>
                <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
            </block>
        </block>

    </reference>
</catalog_category_default>

因此,Magento的顶级设置就是典型的。当类别页面落在块上时,任何想法都会在内容中正确显示,然后再在结束标记之前显示。

任何帮助都会很棒。

1 个答案:

答案 0 :(得分:0)

我不是开发人员也不确定我的解决方案适合您。

您可以尝试更改

<block type="tsb_category/view" my_custom="Test" 
       template="category/view.phtml" 
       before="category.products" />

<block type="tsb_category/view" my_custom="Test" 
       name="category_view" as="category_view" 
       template="category/view.phtml" 
       before="category.products" />
相关问题