Unable to render custom block template - magento

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 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>
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

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.

Related

Magento second header

I have a Magento store with two separate headers. Let's say out of 20 pages 15 use header.phtml and 5 use headerGreen.phtml. I've already created my custom layout module however I can't seem to get the new header to appear on select pages. The new headerGreen.phtml file has been created as well. The issue lies when I try to call the new header in the newly created layout page.
<?php echo $this->getChildHtml('headerGreen') ?>
I dont think I've added it correctly to the local.xml and was hoping someone could help.
<default>
<reference name="header">
<block type="core/template" name="header" template="page/headerGreen.phtml" />
</reference>
</default>
The function getChildHtml is expecting you to send a name of a child in the layout as first parameter
app/code/core/Mage/Core/Block/Abstract.php defines it :
/**
* Retrieve child block HTML
*
* #param string $name
* #param boolean $useCache
* #param boolean $sorted
* #return string
*/
public function getChildHtml($name = '', $useCache = true, $sorted = false)
{
// the code is does not really matter here
}
So based on your layout you should actually do
<?php echo $this->getChildHtml('header') ?>
Because header is the name attribute in this xml node of your layout :
<block type="core/template" name="header" template="page/headerGreen.phtml" />
As said in the comments, your layout is also looking strange because you are actually telling that your new header is going to be a child of the current header.
Two thinks you can do :
Use the powerfulness of the action nodes :
<default>
<reference name="header">
<action method="setTemplate">
<template>page/headerGreen.phtml</template>
</action>
</reference>
</default>
Or redefine the whole header block
<default>
<reference name="root">
<block type="core/template" name="header" as="header" template="page/headerGreen.phtml" />
</reference>
</default>

Magento 1.9.2.1: Color, size attribute of product not showing on onepage checkout

Recently I have added attributes to the product color and size. (configurable products)
When we add to cart, and go to view cart then we see the products with attributes color and size.
I added shopping cart block in onepage checkout in app/design/frontend/smartwave/porto/layout/iwd_opc.xml
<reference name="content">
<block type="checkout/cart" name="checkout.cart" template="checkout/cart.phtml">
<block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="checkout/cart/coupon.phtml"/>
<block type="checkout/cart_totals" name="checkout.cart.totals" as="totals" template="checkout/cart/totals.phtml"/>
<block type="checkout/cart_sidebar" name="checkout.cart.sidebar" as="sidebar" template="checkout/cart/sidebar.phtml"/>
</block>
</reference>
I get the following page after adding shopping cart layout to onepage cart
Now I am stuck here, how should I get the attributes name here?
I have set attributes to be visible on frontend from backend as well.
Code to display products in the cart is on app/design/frontend/smartwave/porto/template/checkout/cart.phtml
<?php foreach($this->getItems() as $_item): ?>
<?php echo $this->getItemHtml($_item) ?>
<?php endforeach ?>
Logic of the code is written over here: app/code/core/Mage/Checkout/Block
public function getItems()
{
if ($this->getCustomItems()) {
return $this->getCustomItems();
}
return parent::getItems();
}
Another way of displaying the products to the cart is: But I dont want to use this code to display the list in the cart:
$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
$productName = $item->getProduct()->getName();
$productPrice = $item->getProduct()->getPrice();
echo "Name: ".$productName." Price: ".$productPrice;
}
I have also tried to add attributes in xml file
app/code/core/Mage/Sales/etc/config.xml
<item>
<product_attributes>
<color/>
<size/>
<condition/>
<sku/>
<type_id/>
<name/>
<status/>
<visibility/>
<price/>
<weight/>
<url_path/>
<url_key/>
<thumbnail/>
<small_image/>
<tax_class_id/>
<special_from_date/>
<special_to_date/>
<special_price/>
<cost/>
<is_recurring/>
<recurring_profile/>
<gift_message_available/>
<msrp_enabled/>
<msrp/>
<msrp_display_actual_price_type/>
</product_attributes>
</item>
So I have just copied the block to the onepage checkout page, but I am not able to understand that why the onepage checkout page is not showing product's size and color ("/onepage/") and it is strange that color and sizes can be seen on checkout page ("checkout/cart/")
Thanks in advance
I believe you have not added itemrendere in your layout. Basically cart items are listed using checkout/cart/item/default.phtml.
I will suggest to look over checkout.xml layout file and copy the whole layout <reference name="content"> node into your iwd and then start removing the template includes which you do not require.
Another method is using layout updates which will extend your iwd layout to checkout_cart. Which will do same thing above. You need to use <remove name=""> tag to remove extra cart includes from your iwd handle.
Finally I found the solution with the help of Blastfreak
Include following lines in app/design/frontend/smartwave/porto/layout/iwd_opc.xml
<reference name="content">
<block type="checkout/cart" name="checkout.cart" template="checkout/cart.phtml">
<block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="checkout/cart/coupon.phtml"/>
<block type="checkout/cart_totals" name="checkout.cart.totals" as="totals" template="checkout/cart/totals.phtml"/>
<block type="checkout/cart_sidebar" name="checkout.cart.sidebar" as="sidebar" template="checkout/cart/sidebar.phtml"/>
<action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/item/default.phtml</template></action>
<action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/item/default.phtml</template></action>
<action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/item/default.phtml</template></action>
</block>
</reference>
Output page:

where is this method doing in admin controller (Grid Serializer)?

<?php
class Excellence_Manager_Adminhtml_ManagerController extends Mage_Adminhtml_Controller_action
{
public function customerAction(){
$this->loadLayout();
$this->getLayout()->getBlock('customer.grid')
->setCustomers($this->getRequest()->getPost('customers', null));
$this->renderLayout();
}
I am following this grid serializer tute . I just can not understand where is this setCustomers coming from ?
Even in other tutes I saw that setClent(), setDog() etc. But where is get or it's not from the database either. not in the layout either I think. Please help thanks.
<manager_adminhtml_manager_customer>
<block type="core/text_list" name="root" output="toHtml">
<block type="manager/adminhtml_manager_edit_tab_grid" name="customer.grid"/>
<block type="adminhtml/widget_grid_serializer" name="grid_serializer">
<reference name="grid_serializer">
<action method="initSerializerBlock">
<grid_block_name>customer.grid</grid_block_name>
<data_callback>getSelectedCustomers</data_callback>
<hidden_input_name>links[customers]</hidden_input_name>
<reload_param_name>customers</reload_param_name>
</action>
<action method="addColumnInputName">
<input_name>position</input_name>
</action>
</reference>
</block>
</block>
I found it's not from hidden_input_name or reload_param_name.
__set() is run when writing data to inaccessible properties.
__get() is utilized for reading data from inaccessible properties.
Magento implements so called "Magic Methods" to set data in an object.
They implemented __set and __get which are called, when no method for e.g. setCustomers() is found, and use those methods to do setData('customers', "YOUR_VALUE");

Magento _getUrl call function is duplicating the url to my link

I use the function _getUrl to link the top link I created in my custom module, but for some reason it duplicates the URL. For example, say I want it to link me to:
www.localhost.com/magento/sapna/account/index
instead, it shows:
www.localhost.com/magento/http://index/www.localhost.com/magentosapna/account/index
Here is my function:
const ROUTE_FORM = 'sapna/account/index';
/**
* Retrieve goomer/breeder registariion url
*
* #return string
*/
public function getLoginUrl(){
return $this->_getUrl(self::ROUTE_FORM, $this->getLoginUrlParams());
}
i'm doing in module/Helper/Data.php and i use getUrl it does not work
I wrote this in the Data.php helper file. Can anyone help? I have been through this so many times, but I do not see what is wrong.
Check your customer.xml file for the following :
<customer_logged_out>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer">
<label>Log In</label>
<url helper="customer/getLoginUrl"/>
<title>Log In</title>
<prepare/>
<urlParams/>
<position>100</position>
</action>
</reference>
<remove name="reorder"></remove>
</customer_logged_out>
/* Use <prepare/> instead of <prepare>true</prepare> */
worked for me...!

Magento: page/html_wrapper block is empty

Small part of Page.xml:
<layout version="0.1.0">
....
<default translate="label" module="page">
<label>All Pages</label>
<block type="page/html" name="root" output="toHtml" template="page/2columns-left.phtml">
<block type="page/html_header" name="header" as="header" /> <!-- work -->
<block type="page/html_wrapper" name="u.Top.Menu" as="u_Top_Menu" translate="label"> <!-- doesn't work -->
<label>top menu</label>
<action method="setElementTagName"><value>div</value></action>
<action method="setElementClass"><value>sub-menu</value></action>
</block>
...
</block>
....
And in the 2columns-left.phtml output it:
<?php echo $this->getChildHtml('u_Top_Menu'); ?>
But it always retuns empty value. I'm confused here a bit. What I'm doing wrong here?
This is what happens when you forget to add the children block to the html wrapper block. Look at this block class source code:
class Mage_Page_Block_Html_Wrapper extends Mage_Core_Block_Abstract
{
/**
* Whether block should render its content if there are no children (no)
* #var bool
*/
protected $_dependsOnChildren = true;
/**
* Render the wrapper element html
* Supports different optional parameters, set in data by keys:
* - element_tag_name (div by default)
* - element_id
* - element_class
* - element_other_attributes
*
* Renders all children inside the element.
*
* #return string
*/
protected function _toHtml()
{
$html = empty($this->_children) ? '' : trim($this->getChildHtml('', true, true));
if ($this->_dependsOnChildren && empty($html)) {
return '';
}
...
So far as I can tell you are doing everything correct. The thing that normally trips people up is the as vs name issue whereby a block is referred in xml via it's name, but in templates via it's as. You don't appear to have fallen into this trap, so my best guess is that your cache hasn't been cleaned. An rm -rf var/cache/mage-* should hopefully fix the issue.
Zyava is correct, but I have a workaround!
If you don't want to add children to the block, but still need it to render, there is a class function (dependsOnChildren) that allows you to set this _dependsOnChildren flag from your layout XML like so:
<block type="page/html_wrapper" name="u.Top.Menu" as="u_Top_Menu" translate="label"> <!-- doesn't work -->
<label>top menu</label>
<action method="setElementTagName"><value>div</value></action>
<action method="setElementClass"><value>sub-menu</value></action>
<!-- This will tell PhP to call $blockClass->dependsOnChildren(0); before rendering. -->
<action method="dependsOnChildren"><value>0</value></action>
</block>
Here is that function (for reference)
app/code/core/Mage/Page/Block/Html/Wrapper.php # Line 80
/**
* Setter whether this block depends on children
* #param $depends
* #return Mage_Page_Block_Html_Wrapper
*/
public function dependsOnChildren($depends = '0')
{
$this->_dependsOnChildren = (bool)(int)$depends;
return $this;
}

Resources