Karan Kumar
Karan Kumar

Reputation: 5

Unable to render custom block template

I am using magento 1.7 and i have create custom widget block but some reason i am unable to render template i don't know why please give right solution and what is the problem with my code if i return string code from _toHtml then its showing code but through phtml template file i am unable to render anything

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

and here is following my 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 [email protected] 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>

Please if you think question need more improvement then you can edit but please don't do unnecessary down vote this is my problem i am sharing here

Upvotes: 0

Views: 1988

Answers (1)

Pavel Novitsky
Pavel Novitsky

Reputation: 1694

Why do you extend your block from Mage_Core_Block_Abstract? Abstract class has no property $_template and your _toHtml() method does not implement template output. You need to extend from Mage_Core_Block_Template class.

Magento has several block types. You can find good list in this answer.

Upvotes: 1

Related Questions