Magento, Static Block won't render? - magento

this is my local.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="root">
<block type="core/text_list" name="banner" as="banner" translate="label">
<label>Banner Area</label>
</block>
</reference>
<reference name="bannerblock">
<block type="core/template" name="bannerblock" template="banner.phtml" />
</reference>
</default>
</layout>
this is my 1column.phtml
<?php echo $this->getChildHtml('banner') ?>
I am not sure why it is not rendered. I think it might have to do with the placement of banner.phtml
should I put in
app/design/frontend/x/x/template/
or inside
app/design/frontend/x/x/template/page/html/
how do magenta find out?

You are referencing "bannerblock" block from inside of "bannerblock". Try moving the "bannerblock" block delaration into the "root" reference node:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="root">
<block type="core/text_list" name="banner" as="banner" translate="label">
<label>Banner Area</label>
</block>
<block type="core/template" name="bannerblock" template="banner.phtml" />
</reference>
</default>
</layout>

Related

Nested block and getChildHtml() in magento

I have some trouble when i get data with function getChildHtml() .
Here is my layout.xml file
<?xml version="1.0"?>
<layout version="0.1.0">
<hello_index_index>
<reference name="content">
<block type="hello/hello" name="title" template="hello/title.phtml">
<block type="hello/hello" name="title1" template="hello/title1.phtml">
<block type="hello/hello" name="title2" template="hello/title2.phtml"/>
</block>
</block>
</reference>
</hello_index_index>
</layout>
when i try print data in file title2.phtml to the screen with code is
echo $this->getChildHtml('title2');
OR
echo $this->getChildHtml('title1');
In the first way is no data displayed on the screen .
In the second way have data displayed on the screen but only data in file title1.phtml .
So how to display the data in file title2.phtml
Thank everybody .
As your code example is somewhat obscured, it's difficult for me to understand what your blocks actually are and/or do.
Remove the association between "title1" and "title2", then try rendering your block(s) with getChildHtml again.
<?xml version="1.0"?>
<layout version="0.1.0">
<hello_index_index>
<reference name="content">
<block name="title" template="hello/title.phtml" type="hello/hello">
<block name="title1" template="hello/title1.phtml" type="hello/hello" />
<block name="title2" template="hello/title2.phtml" type="hello/hello" />
</block>
</reference>
</hello_index_index>
</layout>
<block type="hello/hello" name="title" template="hello/title.phtml">
<block type="hello/hello" name="title1" template="hello/title1.phtml">
<block type="hello/hello" name="title2" template="hello/title2.phtml"/>
</block>
</block>
in title.phtml write $this->getChildHtml('title1'); and in title1.phtml write
$this->getChildHtml('title2')
because magento blocks can render only "child" blocks when using "getChildHtml()"

How can i display header only homepage in Magento?

I want to display header only homepage.
How can i disable header other page?
Hi If your website having one column layout then open the 1column.phtml file and
replace this line
<?php echo $this->getChildHtml('header') ?>
with this,
<?php $page= Mage::getSingleton('cms/page')->getIdentifier();?>
<?php if($page=='home'){ ?>
<?php echo $this->getChildHtml('header') ?>
<?php } ?>
If you want remove this header using xml then follow below steps
step1:create local.xml under app/design/frontend/yourpackage/yourtemplate/layout
code of local.xml is
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="root">
<remove name="headerone"/>
</reference>
</default>
<cms_index_index >
<reference name="root">
<block type="page/html_header" name="header" as="header">
<block type="page/template_links" name="top.links" as="topLinks"/>
<block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
<block type="core/text_list" name="top.menu" as="topMenu" translate="label">
<label>Navigation Bar</label>
<block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/>
</block>
<block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
<label>Page Header</label>
<action method="setElementClass"><value>top-container</value></action>
</block>
</block>
</reference>
</cms_index_index>
</layout>
Step2:goto page.xml under app/design/frontend/yourpackage/yourtemplate/layout
Find <block type="page/html_header" name="header" as="header">
change it to
<block type="page/html_header" name="headerone" as="headerone">
You could do this quite easily without any code changes by adding a <remove /> line for the header block in your local.xml and then in the home page layout, adding the header block to the home page in CMS under page layout in the design tab.
Layout is quite powerful in making such a custom mod.

magento - adding a block using local.xml

if I have a template in
app\design\frontend\base\default\template\dir\template.phtml
that look like this
<div class='block block-list'>
<div class='block-title'><strong><span>Some Block</span></strong></div>
<div class='block-content'>
<?php echo "my content"; ?>
</div>
</div>
How can I show it on a catalog page using local.xml? Shouldn't this code work?
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="right">
<block type="core/template"
name="somename"
template="dir/template.phtml" />
</reference>
</default>
</layout>
I think you can not have custom layout handle<catalog_category_default translate="label"> inside default layout handle<default>
Correct me if I am wrong.
You have to use template reference name before that reference tag.
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<catalog_category_default translate="label">
<reference name="right">
<block type="core/template"
name="somename"
template="dir/template.phtml" />
</reference>
</catalog_category_default>
</default>
</layout>

I am writing my first Magento module and need to overide a default template file

I am trying to override the shipping block in the cart page. However, my code just duplicates the shipping file twice. The weird thing is it duplicates my shipping file twice and not one of each. How can I disable the original shipping.phtml file and make magento only use my layout?
Here is my code:
app/etc/modules/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Module_Name>
<!-- Whether our module is active: true or false -->
<active>true</active>
<!-- Which code pool to use: core, community or local -->
<codePool>local</codePool>
</Module_Name>
</modules>
</config>
etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- The root node for Magento module configuration -->
<config>
<!--
The module's node contains basic
information about each Magento module
-->
<modules>
<!--
This must exactly match the namespace and module's folder
names, with directory separators replaced by underscores
-->
<Module_Name>
<!-- The version of our module, starting at 0.0.1 -->
<version>0.0.1</version>
</Module_Name>
</modules>
<frontend>
<layout>
<updates>
<brands>
<file>shipping.xml</file>
</brands>
</updates>
</layout>
</frontend>
</config>
My theme Layout XML File:
<?xml version="1.0"?>
<layout version="0.1.0">
<!--
Default layout, loads most of the pages
-->
<checkout_cart_index translate="label">
<label>Shopping Cart</label>
<remove name="right"/>
<remove name="left"/>
<!-- Mage_Checkout -->
<reference name="head">
<action method="addCss"><stylesheet>css/shipping.css</stylesheet> </action>
</reference>
<reference name="content">
<block type="checkout/cart" name="checkout.cart">
<action method="setCartTemplate"><value>checkout/cart.phtml</value></action>
<action method="setEmptyTemplate"><value>checkout/cart/noItems.phtml</value></action>
<action method="chooseTemplate"/>
<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 type="core/text_list" name="checkout.cart.top_methods" as="top_methods" translate="label">
<label>Payment Methods Before Checkout Button</label>
<block type="checkout/onepage_link" name="checkout.cart.methods.onepage" template="checkout/onepage/link.phtml"/>
</block>
<block type="page/html_wrapper" name="checkout.cart.form.before" as="form_before" translate="label">
<label>Shopping Cart Form Before</label>
</block>
<block type="core/text_list" name="checkout.cart.methods" as="methods" translate="label">
<label>Payment Methods After Checkout Button</label>
<block type="checkout/onepage_link" name="checkout.cart.methods.onepage" template="checkout/onepage/link.phtml"/>
<block type="checkout/multishipping_link" name="checkout.cart.methods.multishipping" template="checkout/multishipping/link.phtml"/>
</block>
<block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="checkout/cart/coupon.phtml"/>
<block type="checkout/cart_shipping" name="checkout.cart.shipping" as="shipping" template="module/shipping.phtml"/>
<block type="checkout/cart_crosssell" name="checkout.cart.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml"/>
<block type="checkout/cart_totals" name="checkout.cart.totals" as="totals" template="checkout/cart/totals.phtml"/>
</block>
</reference>
<block type="core/text_list" name="additional.product.info" translate="label">
<label>Additional Product Info</label>
</block>
</checkout_cart_index>
</layout>
You don't need to copy all that layout code. Just change the template:
<reference name="checkout.cart.shipping">
<action method="setTemplate"><template>path/to/template.phtml</template></action>
</reference>
This might happen due
<reference name="content">
<block type="checkout/cart" name="checkout.cart">
<action method="setCartTemplate"><value>checkout/cart.phtml</value></action>
<action method="setEmptyTemplate"><value>checkout/cart/noItems.phtml</value></action>
<action method="chooseTemplate"/>
<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 type="core/text_list" name="checkout.cart.top_methods" as="top_methods" translate="label">
<label>Payment Methods Before Checkout Button</label>
<block type="checkout/onepage_link" name="checkout.cart.methods.onepage" template="checkout/onepage/link.phtml"/>
</block>
<block type="page/html_wrapper" name="checkout.cart.form.before" as="form_before" translate="label">
<label>Shopping Cart Form Before</label>
</block>
<block type="core/text_list" name="checkout.cart.methods" as="methods" translate="label">
<label>Payment Methods After Checkout Button</label>
<block type="checkout/onepage_link" name="checkout.cart.methods.onepage" template="checkout/onepage/link.phtml"/>
<block type="checkout/multishipping_link" name="checkout.cart.methods.multishipping" template="checkout/multishipping/link.phtml"/>
</block>
<block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="checkout/cart/coupon.phtml"/>
<block type="checkout/cart_shipping" name="checkout.cart.shipping" as="shipping" template="Beckin/dropdownshipping/drop_down_shipping.phtml"/>
<block type="checkout/cart_crosssell" name="checkout.cart.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml"/>
<block type="checkout/cart_totals" name="checkout.cart.totals" as="totals" template="checkout/cart/totals.phtml"/>
</block>
</reference>
is present in the checkout.xml and now your shipping module layout ,(i guess drop_down_shipping.xml) has a handle checkout_cart_index which has same code as result it is called twice.
I would suggest that in your custom module layout only update the change that you made for the handler rather than coping all.
Hope this help.

Magento - Add CMS Block to One Page

I have this code in a xml layout file:
<reference name="left">
<block type="blog/blog" name="left.blog.menu" before="-">
<action method="setTemplate" ifconfig="blog/menu/left">
<template>aw_blog/menu.phtml</template>
</action>
<block type="blog/tags" name="blog_tags" />
</block>
</reference>
I want to add a cms static block to the blog pages using this code:
<block type="cms/block" name="brand_list">
<action method="setBlockId"><block_id>brand_list</block_id></action>
</block>
If I add it in directly after this line:
<reference name="left">
It works but it is then displayed on every page. How can I get it to show only on the blog pages?
Thanks.
Edit: Here is the entire xml file:
<layout version="0.1.0">
<default>
<reference name="footer_links">
<block type="blog/blog" name="add.blog.footer">
<block type="blog/tags" name="blog_tags" />
<action method="addFooterLink" ifconfig="blog/menu/footer"></action>
</block>
</reference>
<reference name="right">
<block type="blog/blog" name="right.blog.menu" before="-">
<action method="setTemplate" ifconfig="blog/menu/right" ifvalue="1">
<template>aw_blog/menu.phtml</template>
</action>
<block type="blog/tags" name="blog_tags" />
</block>
</reference>
<reference name="left">
<block type="blog/blog" name="left.blog.menu" before="-">
<action method="setTemplate" ifconfig="blog/menu/left">
<template>aw_blog/menu.phtml</template>
</action>
<block type="blog/tags" name="blog_tags" />
</block>
</reference>
<reference name="top.links">
<block type="blog/blog" name="add.blog.link">
<action method="addTopLink" ifconfig="blog/menu/top"></action>
<block type="blog/tags" name="blog_tags" />
</block>
</reference>
<reference name="head">
<action method="addItem"><type>skin_css</type><name>aw_blog/css/style.css</name></action>
</reference>
</default>
<blog_index_index>
<reference name="content">
<block type="blog/blog" name="blog" template="aw_blog/blog.phtml"/>
</reference>
</blog_index_index>
<blog_index_list>
<reference name="content">
<block type="blog/blog" name="blog" template="aw_blog/blog.phtml"/>
</reference>
</blog_index_list>
<blog_post_view>
<reference name="content">
<block type="blog/post" name="post" template="aw_blog/post.phtml">
<block type="socialbookmarking/bookmarks" name="bookmarks" template="bookmarks/bookmarks.phtml"/>
</block>
</reference>
</blog_post_view>
<blog_cat_view>
<reference name="content">
<block type="blog/cat" name="cat" template="aw_blog/cat.phtml" />
</reference>
</blog_cat_view>
<blog_rss_index>
<block type="blog/rss" output="toHtml" name="rss.blog.new"/>
</blog_rss_index>
</layout>
if it's going inside a section then it will be applied to all pages, you want to put the and its contents inside the sections (there'll be the listing page and individual post pages - the sections should already exist in the aw_blog.xml file
It appears on all pages, because you probably put the code in the section of the layout xml. Just put into a section named after the route where it should appear.
So try:
<blog>
<reference name="left">
<block type="cms/block" name="brand_list">
<action method="setBlockId"><block_id>brand_list</block_id></action>
</block>
</reference>
</blog>
Change XML inside folder theme/layout for example page.xml add something like this to header:
<block type="page/html_header" name="header" as="header">
<!-- ... some origin code ... -->
<block type="page/html" name="custom_block" as="flashHeader" template="customer/custom_header.phtml"/>
</block>
Create file customer/custom_header.phtml with your custom html code.
Inside template page/html/header.phtml you can add something like this:
$dataCurrentPage = $this->getHelper('cms/page')->getPage()->getData();
$page_id = (isset($dataCurrentPage['identifier'])) ? $dataCurrentPage['identifier'] : null;
if ($page_id == 'home' ) { echo this->getChildHtml('flashHeader') }
Flash banner will be show only on homepage.
You can definitely use the custom layout update to place your own static block on left without any coding.
You need to create a static block and then put its reference into custom layout update
<reference name="left">
<block type="cms/block" name="my_left_block" before="-">
<action method="setBlockId"><block_id>my_left_block</block_id></action>
</block>
to view an example follow the link below
https://lampjs.wordpress.com/2015/07/06/magento-add-static-cms-block-to-category-page-on-left/

Resources