Nested block and getChildHtml() in magento - 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()"

Related

Magento, Static Block won't render?

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>

Custom page breadcrumb name in magento

I'm trying to change the breadcrumb that is showed on my blog page.
Now I have something like" Home / Blog ", but I want it to show like " Home / NewNameHere ".
I went to my blog.xml file and where I had this:
<blog_index_index>
<reference name="content">
<block type="blog/blog" name="blog" template="blog/blog.phtml"/>
</reference>
</blog_index_index>
Changed to this:
<blog_index_index>
<reference name="content">
<block type="blog/blog" name="blog" template="blog/blog.phtml"/>
<action method="addCrumb">
<name>newnamehere</name>
<params>
<label>newnamehere</label>
<title>newnamehere</title>
<link> /blog/</link>
</params>
</action>
</reference>
</blog_index_index>
But nothing has changed. Any help would be appreciated.
Try the below code:
<blog_index_index>
<reference name="content">
<block type="blog/blog" name="blog" template="blog/blog.phtml"/>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
<action method="addCrumb">
<name>NewName</name>
<params>
<label>NewName</label>
<title>NewName</title>
<link>/blog/</link>
</params>
</action>
</block>
</reference>
</blog_index_index>
And in your blog.phtml call like this
<?php echo $this->getLayout()->getBlock('breadcrumbs')->toHtml();?>

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: Add Block Before Footer

I'm using GrayScale template, and I want to move the recent viewed to a block before the footer.
I need this block with a different color from footer.
So, I removed this block of page.xml:
<block type="reports/product_viewed" before="right.permanent.callout" name="right.reports.product.viewed" template="reports/product_viewed.phtml" />
And added to footer block of page.xml:
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
<block type="reports/product_viewed" before="right.permanent.callout" name="right.reports.product.viewed" template="reports/product_viewed.phtml" />
<block type="page/html_wrapper" name="bottom.container" as="bottomContainer" translate="label">
<label>Page Footer</label>
<action method="setElementClass"><value>bottom-container</value></action>
</block>
<block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
<block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>
</block>
Perfect!
But, I need this block before footer and not inside...
How can I do this???
Thanks!
Open your Page.xml file and find the following block
<block type="page/html_footer" name="footer" as="footer" template="page/htmlfooter.phtml">
It should be arond line number 100.
Inside the block paste the following code
<block type="reports/product_viewed" name="reports.product.viewed" as="recently_viewed" template="reports/product_viewed.phtml">
<action method="setColumnCount"><columns>4</columns></action>
<action method="setItemLimit"><type>recently_viewed</type><limit>4</limit></action>
</block>
The block should look like this
Now open your footer.phtml file and before the footer, i.e.
<div class="footer-container">
write the following code
<?php echo $this->getChildHtml('recently_viewed') ?>
And change the child block calling like the following
Now any logged in user will be able to view their recently viewed product and yes, it is outside the footer.
You can style it according to your needs, and you can also set the column count from the block itself.
Enjoy.
Try adding this right above the 'footer' section:
<block type="core/text_list" name="review.before.footer" as="review.before.footer" translate="label">
<block type="reports/product_viewed" before="right.permanent.callout" name="right.reports.product.viewed" template="reports/product_viewed.phtml" />
</block>

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