Creating cms block and calling in phtml - magento

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'); ?>

Related

Magento 1.9 breadcrumbs always empty

I'm working on a magento ecommerce, I'm not the one who configured it or anything, I'm just doing his CSS, however, the site does not display the breadcrumbs.
Inside the "page / html / breadcrumbs.phtml" file I made a var_dump in the $ crumbs variable and it is always empty.
In the XML only in one situation the breadcrumbs is displayed in the frontend, when I enter the code inside the "default" tag if I put this code inside "customer_account_login" nothing will be displayed on the front.
Code of breadcrumbs.phtml:
<?php if($crumbs && is_array($crumbs)): ?>
<div class="breadcrumbs">
<ul>
<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
<li class="<?php echo $_crumbName ?>">
<?php if($_crumbInfo['link']): ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong>
<?php else: ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
Here part of code of "customer.xml"
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<!-- Mage_Customer -->
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>10</position></action>
</reference>
<!-- HERE BREADCRUMBS DISPLAYS ON ALL PAGES THE SAME CONTENT "HOME / MY ACCOUNT" -->
<reference name="breadcrumbs">
<action method="addCrumb">
<crumbName>Home</crumbName>
<crumbInfo><label>Home</label><title>Home</title><link>/</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>My Account</crumbName>
<crumbInfo><label>My Account</label><title>My Account</title><link>/customer/account/</link></crumbInfo>
</action>
</reference>
</default>
<!-- Load this update on every page when customer is logged in -->
<customer_logged_in>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>100</position></action>
</reference>
</customer_logged_in>
<!-- Load this update on every page when customer is logged out -->
<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>
<!-- Layout for customer login page -->
<customer_account_login translate="label">
<label>Customer Account Login Form</label>
<!-- Mage_Customer -->
<remove name="right"/>
<remove name="left"/>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml" />
</reference>
</customer_account_login>
If I move the breadcrumbs code from "< default >" to the "< customer_account_login translate="label" >" for example, all screens returns the breadcrumbs as null.
I have no idea what's going on. I just wish all the screens had their breadcrumbs being displayed.
Check that breadcrumbs are actually enabled in the back end admin panel like below.

Add Banner Below Menu in Category Page

I need to add the category banner below the Breadcrumbs.
I have tried by adding new reference
<?php echo $this->getChildHtml('category_banner') ?>
in the 2columns-left.phtml
and in local.xml
<catalog_category_view>
<reference name="category_banner">
<block type="core/template" name="topbanner" template="catalog/category/category-image.phtml" before="-"></block>
</reference>
</catalog_category_view>
<catalog_category_default translate="label">
<reference name="category_banner">
<block type="core/template" name="banner" template="catalog/category/category-image.phtml"></block>
</reference>
</catalog_category_default>
But output is not coming.
Added new line inside the all layout i.e 2columns-left.phtml etc.
<?php echo $this->getChildHtml('category_banner') ?>
added below line inside your xml
<catalog_category_view>
<reference name="root">
<block type="core/template" name="category_banner" template="catalog/category/category-image.phtml" before="-"></block>
</reference>
</catalog_category_view>

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 show categories on left sidebar on a page

I can't manage to show on a page, on the left side the categories.
I selected for the page under Design - layout to 3 columns,
Right side shows fine, but nothing on left side.
New to magento so I'm not sure in which file in the template I have to look for.
Its a custom template installed so I got so far to:
app/design/frontend/default/f001/template/
but not sure now if to look under catalog or page folders
Go to layout Xml folder..
Blockquote /app/design/frontend/default/default/layout/catalog.xml
Open this Xml file and paste this code.
<reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/left_nav.phtml" />
</reference>
further open this file ..
/app/design/frontend/default/default/template/catalog/navigation/left_nav.phtml
paste this code:
<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat = $obj->getCurrentCategory();
$current_cat = (is_object($current_cat) ? $current_cat->getName() : '');
foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
echo '<li class="current">'.$cat->getName()."\n<ul>\n";
foreach ($obj->getCurrentChildCategories() as $subcat) {
echo '<li>'.$subcat->getName()."</li>\n";
}
echo "</ul>\n</li>\n";
} else {
echo '<li>'.$cat->getName()."</li>\n";
}
}
?>
Go to Layout folder
i.e.
app/design/frontend/default/f001/layout/
open any xml file e.g. catalog.xml and under tags
<default>
</default>
paste in this code
<reference name="left">
<block type="catalog/navigation" name="left_categories_nav" before="-" template="catalog/navigation/left.phtml"/>
</reference>
like this
<default>
<reference name="left">
<block type="catalog/navigation" name="left_categories_nav" before="-" template="catalog/navigation/left.phtml"/>
</reference>
</default>
But make sure to comment this block on line number 79.
<!-- <reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference> -->
To move the categories from the right sidebar to the left sidebar you'll need to do this:
(1) Open app/design/frontend/default/f001/layout/ and find a file called local.xml - If it does not exist, create it.
Paste the following inside and save.
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<!-- Left Categories Begin-->
<reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" before="-" template="catalog/navigation/left.phtml"/>
</reference>
<!-- Left Categories End-->
</default>
</layout>
(2) Open app/design/frontend/default/f001/layout/catalog.xml
Inside "Category default layout", look for something like this and comment this line out (like so)-
<!-- <reference name="right">
<block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference> -->
That will prevent the categories from displaying on both sidebars, assuming you're using a 3 column.
The reference name, as you might have guessed, refers to each sidebar. You'll need to make sure that the reference name for "left" contains the left categories, and make sure the right does not (controlled in layout, not template files).
Add this in left static block
<p>Left side bar {{block type="core/template" template="catalog/navigation/left.phtml"}}</p>
add left.phtml in yourtemplatename/template/catalog/navigation/left.phtml
<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat = $obj->getCurrentCategory();
$current_cat = (is_object($current_cat) ? $current_cat->getName() : '');
foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
echo '<li class="current">'.$cat->getName()."\n<ul>\n";
foreach ($obj->getCurrentChildCategories() as $subcat) {
echo '<li>'.$subcat->getName()."</li>\n";
}
echo "</ul>\n</li>\n";
} else {
echo '<li>'.$cat->getName()."</li>\n";
}
}
?>

Exact Placement of childHtml Block (unexpected result)

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

Resources