Exact Placement of childHtml Block (unexpected result) - magento

I am trying to place a new phtml block at a specific place within another phtml page and I am not getting the results I expected - any advice would be much appreciated.
Specifically, I created a new childHtml block for the cart page in my module's xml layout file:
<layout version="0.1.0">
<checkout_cart_index>
<reference name="head">
<action method="addJs"><script>varien/product.js</script></action>
<action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
</reference>
<reference name="content">
<block type="delivery/frontend_checkout_cart_delivery" name="delivery.container" as="delivery" template="unleaded/delivery/checkout/cart/shipping/delivery.phtml"/>
<block type="core/html_calendar" name="delivery_html_calendar" as="delivery_html_calendar" template="page/js/calendar.phtml"/>
</reference>
</checkout_cart_index>
</layout>
Next I made a call to $this->getChildHtml('delivery') in my modified checkout/cart/shipping.phtml template where I wanted it placed:
....
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
....
<?php foreach ($_rates as $_rate): ?>
....
<li>
<?php if ($_rate->getCode() == 'delivery'): ?>
<?php echo $this->getChildHtml('delivery'); ?>
<?php endif; ?>
</li>
....
<?php endforeach; ?>
....
<?php endforeach; ?>
....
What I wanted / expected was to see my block output where I inserted it, but instead it is being output at the very bottom of the page (see screenshot). I am almost certain my mistake is an xml / layout based mistake, but I don't know what?

You call getChildHtml() from within the checkout.cart.shipping block, but add your new block to content. Instead of,
<reference name="content">
...you simply need to say which block your new one will be the child of.
<reference name="checkout.cart.shipping">

Related

Creating cms block and calling in phtml

I just created a cms block from magento admin panel and now I want to get it into the phtml I tried this way:
<?php
$currentview = Mage::app()->getStore()->getCode();
if($currentview = 'default'){
echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1')->toHtml();
}
else if($currentview = 'it'){
echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml();
}
?>
I am getting cms block but if statement not working how can I make it working ?
If you have created CMS block named ostore_footerb1-it from admin panel.
Then following will be code to call them in .phtml
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml();
?>
Another way to do this is :
In the layout (app/design/frontend/your_theme/layout/default.xml):
<default>
<cms_page> <!-- need to be redefined for your needs -->
<reference name="content">
<block type="cms/block" name="cms_ostore_footerb1-it" as="cms_newest_product">
<action method="setBlockId"><block_id>ostore_footerb1-it</block_id></action>
</block>
</reference>
</cms_page>
</default>
In your phtml template:
<?php echo $this->getChildHtml('ostore_footerb1-it'); ?>
To get static block in phtml file
echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml();
Try this:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml(); ?>
Or this:
add this piece to the layout:
<default>
<cms_page> <!-- need to be redefined for your needs -->
<reference name="content">
<block type="cms/block" name="ostore_footerb1-it" as="ostore_footerb1-it">
<action method="setBlockId"><block_id>ostore_footerb1-it</block_id></action>
</block>
</reference>
</cms_page>
</default>
and call in phtml
<?php echo $this->getChildHtml('ostore_footerb1-it'); ?>

how to remove the 'home' link from top menu in magento?

I have a website where i don't want the 'home' link in top menu, I just want to remove or disable it...I have tried this link
http://www.magentocommerce.com/boards/viewthread/60059/
but it didn't find any code in top.phtml (app > design > frontend > default (or whatever theme you have) > catalog > navigation > top.phtml ) like-
<li> yada /home statement </li>
or
<li><?php echo $this->__('Home') ?></li>
I have only
<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<ul id="nav">
<?php echo $_menu ?>
</ul>
</div>
<?php endif ?>
Please give a solution.
I already tried using xml in customer.xml file but may be I didn't use it in proper xml file or proper code.
<reference name="top.links">
<action method="removeLinkByUrl">
<url helper="core/url/getHomeUrl" />
</action>
</reference>
Try this in the local.xml file of your active theme.
<default>
<reference name="root">
<reference name="top.links">
<action method="removeLinkByUrl"><url helper="core/url/getHomeUrl"/></action>
</reference>
</reference>
</default>
As a hack you can hide it using css
find the class and add .class { display:none }
At last, I figured it out.The Home link is there because of the menu plugin(custom responsive menu'). I disabled it from backend.

How do I add the proceed to checkout button outside of the cart page using layout.xml?

I believe this is the code within a phtml file that creates the "Proceed to Checkout" button:
<?php if(!$this->hasError()): ?>
<ul class="checkout-types">
<?php foreach ($this->getMethods('top_methods') as $method): ?>
<?php if ($methodHtml = $this->getMethodHtml($method)): ?>
<li><?php echo $methodHtml; ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
However when I add it to another phtml file that is a sibling to cart.phtml I get an error saying that an invalid argument is being supplied to the foreach.
I then tried adding the block:
<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>
taken from the checkout.xml layout file, to my own block, adfter tht totals block:
<block type="page/html" name="checkout_process" as="checkout_process" template="page/html/checkout_process.phtml">
<block type="checkout/cart_totals" name="checkout.cart.totals" as="totals" template="checkout/cart/totals.phtml"/>
</block>
However this did nothing, am I missing something, I thought this would allow me to include the button?
Where did you place that code? Not all blocks are printed automaticly but need to printed with $this->getChildHtml('your_block') (see magento-layouts-blocks-and-templates).
Here is a minimal example for adding this button to right column, I placed it in local.xml layout file:
<layout version="0.1.0">
<default>
<reference name="right">
<block type="checkout/onepage_link" name="my.cart.button" template="checkout/onepage/link.phtml"/>
</reference>
</default>

Magento calling a catalog/product_list type block from product page

I'm using a simple custom block to list products from a given category in the side bar. It works fine when called as
<block type="catalog/product_list" before="-" name="product.leftnav" as="product.leftnav" template="catalog/product/training_leftlist.phtml" />
On all pages except the product pages, where it causes an error (I get the item page with the 404 page below it).
Is there a better block type I should be using, or a different way of calling it on the product page?
Template file is:
<?php
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status',1)
->addStoreFilter()
->addCategoryFilter(Mage::getModel('catalog/category')->load(12));
$products->setPageSize(4)->setCurPage(1);
$_helper = $this->helper('catalog/output');
Then print the items with something like
if(count($products>0)) echo "<ul>";
foreach($products as $_product):?>
<li>
<h2 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>
</li>
<?php endforeach;?>
<?php if(count($products>0)) echo "</ul>";?>
The answer turned out to use a different block type for each place.
For the non-product pages
<block type="catalog/product_list" before="-" name="product.leftnav" as="product.leftnav" template="catalog/product/training_leftlist.phtml" />
Then for the Product pages use type="catalog/product_list_related". Remembering to remove the above too, e.g:
<catalog_product_view>
<remove name="product.leftnav" />
<!-- Left bar product list-->
<reference name="left">
<block type="catalog/product_list_related" before="-" name="product.leftnav.view" as="product.leftnav.view" template="catalog/product/training_leftlist.phtml" />
</reference>
</catalog_product_view>

Magento: Move product filters

As default, the available product filters are displayed in the left sidebar. But I'd like to display them above the product list instead.
I simply tried to just copy the following code from /template/catalog/layer/view.phtml to /template/catalog/product/list.phtml:
<p class="block-subtitle"><?php echo $this->__('Shopping Options') ?></p>
<dl id="narrow-by-list">
<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getItemsCount()): ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd><?php echo $_filter->getHtml() ?></dd>
<?php endif; ?>
<?php endforeach; ?>
</dl>
But apparently it doesn't work that way. How should I do?
Thank you in advance!
You need to make the block (a php class) which uses the filters template a child of the class where you wish to include those filters. This is done in layout XML.
In a local.xml file in your theme's layout folder, do the following:
<?xml version="1.0" ?>
<layout>
<catalog_category_layered>
<!-- remove from left block -->
<reference name="left">
<action method="unsetChild">
<child>catalog.leftnav</child>
</action>
</reference>
<!-- add as child to product list block -->
<reference name="product_list">
<action method="insert">
<child>catalog.leftnav</child>
</action>
</reference>
</catalog_category_layered>
</layout>
using the above, you can simply call <?php echo $this->getChildHtml('catalog.leftnav') ?> inside your custom list template for it to show. You can either style it using CSS, or you can change its template by adding this inside the catalog_category_layered node above:
<reference name="catalog.leftnav">
<action method="setTemplate">
<child>path/to/template.phtml</child>
</action>
</reference>

Resources