无法呈现自定义块模板

时间:2013-01-03 14:03:55

标签: magento magento-1.7

我正在使用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>

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

1 个答案:

答案 0 :(得分:1)

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

Magento有几种块类型。你可以在this回答中找到好的清单。