0

我正在使用magento 1.7并且我已经创建了自定义小部件块但是由于某种原因我无法呈现模板我不知道为什么请给出正确的解决方案如果我从_toHtml返回字符串代码然后它的显示代码我的代码有什么问题但是通过 phtml 模板文件我无法渲染任何东西

block\slider.php

<?php


class XXXX_Slider_Block_Slider extends Mage_Core_Block_Template
{
    /**
     * Constructor. Set template.
     */
    protected function _construct()
    {
        parent::_construct();
        $this->setTemplate('slider/slider.phtml');
    }
    protected function _toHtml()
    {
        return parent::_toHtml();
    }
}


and this is my slider/slider.phtml

slider is executed

这里是我的 cms.xml

<?xml version="1.0"?>
<!--
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
-->
<layout version="0.1.0">
<!--
Default layout, loads most of the pages
-->

    <default>
        <reference name="footer">
            <block type="cms/block" name="cms_footer_links" before="footer_links">
                <!--
                    The content of this block is taken from the database by its block_id.
                    You can manage it in admin CMS -> Static Blocks
                -->
                <action method="setBlockId"><block_id>footer_links</block_id></action>
            </block>
        </reference>
    </default>

    <cms_page translate="label">
        <label>CMS Pages (All)</label>
        <reference name="content">
            <block type="slider/slider" name="easyshop.slider" template="slider/slider.phtml"/>
            <block type="core/template" name="page_content_heading" template="cms/content_heading.phtml"/>
            <block type="page/html_wrapper" name="cms.wrapper" translate="label">
                <label>CMS Content Wrapper</label>
                <action method="setElementClass"><value>std</value></action>
                <block type="cms/page" name="cms_page"/>
            </block>
        </reference>
    </cms_page>

    <cms_index_index translate="label">
        <label>CMS Home Page</label>
        <remove name="cms_page" />
    </cms_index_index>

    <cms_index_defaultindex>
        <remove name="right"/>
        <remove name="left"/>

        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
        </reference>
        <reference name="content">
            <block type="core/template" name="default_home_page" template="cms/default/home.phtml"/>
        </reference>
    </cms_index_defaultindex>

    <cms_index_noroute translate="label">
        <label>CMS No-Route Page</label>
    </cms_index_noroute>

    <cms_index_defaultnoroute>
        <remove name="right"/>
        <remove name="left"/>

        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
        </reference>
        <reference name="content">
            <block type="core/template" name="default_no_route" template="cms/default/no-route.phtml"/>
        </reference>
    </cms_index_defaultnoroute>

</layout>

请如果您认为问题需要更多改进,那么您可以编辑,但请不要做不必要的投票这是我在这里分享的问题

4

1 回答 1

1

你为什么从 Mage_Core_Block_Abstract 扩展你的块?抽象类没有属性 $_template 并且您的 _toHtml() 方法不实现模板输出。您需要从 Mage_Core_Block_Template 类扩展。

Magento 有几种块类型。你可以在这个答案中找到好的列表。

于 2013-01-03T14:15:10.317 回答