Hide category menu using local.xml - magento

How to hide category/menu bar on selected pages like login & registration using local.xml ?
I'm using magento 1.7.0.2

You need to remove block named 'catalog.topnav' for login and registration page handlers. The page handler similar to page URL, but all slashes replaced with '_'. For the login page it will be *customer_account_login* and for the registration page - *customer_account_create*. You can use
<remove name="[blockname]">
or
<action method="unsetChild"><block>[blockname]</block></action>
instructions, first allow you to remove block globally and the second one remove it from certain block.
The Layout update for default magento theme will looks like:
<?xml version="1.0"?>
<layout version="0.1.0">
<customer_account_login>
<remove name="catalog.topnav" />
</customer_account_login>
<customer_account_create>
<remove name="catalog.topnav" />
</customer_account_create>
</layout>
There is some explanation about Magento layouts which can be useful - http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-4-magento-layouts-blocks-and-templates

Remove nodes will be processed after all layout handles are merged, and are a good way to remove a block regardless of which layout handle loaded the block; you just want to get rid of it entirely for some handles! It also removes recursively, so all you need to specify is the layout handle.
On the other hand, you may only want to remove a block from a reference in a specific layout handle, in which case you should use unsetChild. It is often used to remove a block from a reference, but then re-insert the same block with a different position. This would not have been possible with remove.

Related

Layout handle for ALL checkout pages.. I thought it was default

I want to remove a sidebar element for ALL checkout pages. So inside my local.xml I've got something like:
<checkout_default>
<remove name="left.cart"/>
</checkout_default>
but nothing happened... I've tried checkout, checkout_default, checkout_default_default... no bunga.
checkout_cart_index worked but only for the.. cart index page. I tried checkout_cart_default to see if that'd make it work for all cart pages but then it stopped working entirely.
What handle can I use to select ALL checkout pages?
No such handle exists/that's not how handles work.
Layout handles are sort of like events — only they apply strictly the the layout system. Every time you load a URL in the system, certain layout handles are generated. For example, using the online Commerce Bug demo on the cart index page
We can see the five handles generated are
default
STORE_default
THEME_frontend_default_commercebugdemo
checkout_cart_index
customer_logged_out
The checkout_cart_index handle is specific to that page (called the full action name handle), the others fire on all pages. There's no named layout handle that fires for all cart pages.
There are some tools to help you with code reuse. First, you'll need to identify the pages you want to target. Let's say that's checkout_cart_index and checkout_onepage_index.
Then, in you layout update XML file, do something like this
<layouts>
<checkout_cart_index>
<update handle="namespace_packagename_my_custom_handle_name"
</checkout_cart_index>
<checkout_onepage_index>
<update handle="namespace_packagename_my_custom_handle_name"/>
</checkout_onepage_index>
<namespace_packagename_my_custom_handle_name>
<remove name="left.cart"/>
<!-- other updates -->
</namespace_packagename_my_custom_handle_name>
</layouts>
What we've done here is create a custom handle named namespace_packagename_my_custom_handle_name. Then, in each full action name handle, we've told Magento to import the layout rules in our custom handle.
Sometimes Magento itself will do this. For example, Magento uses the customer_account handle to share information between different pages in the customer account section
<sales_order_history translate="label">
<label>Customer My Account Order History</label>
<update handle="customer_account"/>
<!-- ... -->
</sales_order_history>
<!-- ... -->
<sales_order_view translate="label">
<label>Customer My Account Order View</label>
<update handle="customer_account"/>
<!-- ... -->
</sales_order_view translate="label">
However, in the case of the cart pages, there is no such handle.

Magento remove div by local.xml

I know that I can remove blocks by commands, but is one thing more correct, than the other?
Also, would I somehow be able to remove a .div class instead of a block? so that I can remove a .div from a specific page?
Heres the examples of the snippets I know of, to remove blocks.
<remove name="name_name"></remove>
<action method="unsetChild"><name>name.name</name></action>
Remove - remove block from any level, example block AAA is child of the block left that is child of the block content then I can remove it at top level of page layout:
<xxx_index_index>
<remove name="AAA" />
....
unsetChild we can use only within parent of the target block, example if I have this layout:
<default>
<reference name="content">
<block name="BBB" ... />
Then I can remove BBB with method unsetChild
<yyy_index_index>
<reference name="content">
<action method="unsetChild"><name>BBB</name></action>
No, you can't remove a div HTML element unless there is a block comprised of this element and defined in the layout configuration. You can then remove that block and with it the desired div.
There are no provisions to remove HTML elements by using the Magento Layout settings.
You can, however, use layout config to include a javascript file that employs CSS selectors to remove div elements you want.

Placement of Related products - Magento

I have a magento installation where I need to place related products in the center column. This is the easy part. I moved
<block type="catalog/product_list_related" name="catalog.product.related" after="container1" template="catalog/product/list/related.phtml"/>
From the right reference block, to the bottom of the center reference block.
With this I achieved to place the related products in the center column, but all the way at the bottom.
I need the related products to be placed just above the price block in the div (class: product-shop)
I tried to position it with the After/before parameter in the XML but this doesnt seem to work.
If I place the block code higher up in the XML it doesn't show at all.
Moving blocks is quite easy to do correctly (i.e. using best practices). Best practices include not customizing any core layout file when possible as well as working with original block instances rather than reinstantiating them. All of this can be achieve using the custom layout file available to end-implementers.
Create a local.xml file in your custom theme's layout folder e.g. app/design/frontend/[package]/[theme]/layout/local.xml, and in there add the following:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<!--
In Magento v1 a move is accomplished by unsetting in one place
and inserting in another. This is possible using just layout xml
when the "new" parent block is a "Mage_Core_Block_Text_List"
instance. Otherwise a template needs editing.
In Magento v2 there will be actual "move" functionality.
-->
<catalog_product_view>
<reference name="right">
<!-- remove the block name from a parent -->
<action method="unsetChild">
<block>catalog.product.related</block>
</action>
</reference>
<reference name="content">
<!-- add the block name to a parent -->
<action method="insert">
<block>catalog.product.related</block>
</action>
<!--
Mage_Core_Block_Abstract::insert() accepts multiple arguments,
but by default it will insert the added block at the beginning
of the list of child blocks.
-->
</reference>
</catalog_product_view>
</layout>
You can revert the change to the original layout xml file at this point.

Set Magento block template in layout xml

Having trouble setting a block template in Magento's layout xml. I'm attempting to set the template of a child block, not the entire page layout (almost all docs out there explain how to set template of the layout).
Background: I'm updating a layout handle in my custom action, using the <update /> tag in my module's layout xml.
Essentially, I want to reuse the layout and blocks of the built in product view action, but provide custom templates for a few blocks. (Not just overrides, these need to be brand new templates that are only triggered on my custom action and are themselves overrideable).
My layout html:
<?xml version="1.0"?>
<layout version="0.1.0">
<mymodule_product_index>
<update handle="catalog_product_view" />
<reference name="content">
<block type="catalog/product_view"
name="product.info" output="toHtml" template="mymodule/product.phtml" />
</reference>
<reference name="product.info.bundle">
<action method="setTemplate"><template>mymodule/customtemplate.phtml</template></action>
</reference>
</mymodule_product_index>
</layout>
The setTemplate on product.info.bundle never works; it doesn't seem to affect layout at all. I've tried wrapping the <reference> in other <reference> nodes from parent blocks with no effect. Is it possible to replace block templates in this way? I feel that my problem stems from the fact I'm using an <update />.
By the way, I know my layout xml is being loaded and there are no errors, the rest of the file is working fine, caching is disabled, have cleared cache anyway, etc.
Your approach is almost correct.
Two things:
1. Set a new template instead of instantiating a new block
Instead of just assigning a different template to the product.info block, you are creating a new instance with the same name, replacing the original instance, and then the new template is set on that. Instead use this:
<mymodule_product_index>
<update handle="catalog_product_view" />
<reference name="product.info">
<action method="setTemplate">
<template>mymodule/product.phtml</template>
</action>
</reference>
</mymodule_product_index>
That should take care of the product view template in a clean way.
2. Handle processing order
If you look at where the view block product.info.bundle for the bundled products is declared, you will see it happens in the bundle.xml file, in a layout update handle called <PRODUCT_TYPE_bundle>.
Your code is referencing the block from the <[route]_[controller]_[action]> layout handle, i.e. <mymodule_product_index>.
The thing to be aware of here is the processing order of layout handles.
Roughly it is:
<default>
<[route]_[controller]_[action]>
<custom_handles>
The <PRODUCT_TYPE_bundle> handle belongs to the third type of layout handles, which means it is processed after the <mymodule_product_index> handle.
In essence, you are referencing the block product.info.bundle before it has been declared.
To fix this you will need to use the <PRODUCT_TYPE_bundle> handle as well. Of course this will effect every bundled product display. Using layout XML only there is no clean way around that.
Here are a few suggestions how to solve that problem.
You could create a separate route in your module to show the bundled products, and then include the <PRODUCT_TYPE_bundle> handle using an update directive for that page, too.
In your custom action controller, you could add another layout update handle that is processed after <PRODUCT_TYPE_bundle>.
You could use an event observer to set the template on the product.info.bundle block if it is instantiated. One possibility would be the event controller_action_layout_generate_blocks_after.
You get the idea, there are many ways to work around this, but they require PHP.

Magento Store - Remove Block using Update XML

I am using this code in my template file to display a static block in my left sidebar:
<?= $this->getLayout()->createBlock('cms/block')->setBlockId('leftSB1')->toHtml() ?>
I would like to exclude the block from one of my CMS pages. How do I do this?
I think it requires adding code to the 'Layout Update XML' section but I'm not sure what exactly.
Someone else can correct me here, but I'm fairly sure that you're going to have trouble trying to accomplish this given the way you called the block. Normal layout updates allow you to remove blocks, but those are blocks that were also created with the layout (e.g. the Layout object knows about them after you call loadLayout()).
In your case, you create the block on the fly and then immediately use it to echo some HTML. If you want to be able to delete it with layout updates, try moving it into the layout files first, then use the normal layout block removal method:
<reference name="your_parent_block_name">
<remove name="leftSB1"/>
</reference>
Otherwise, you could hide it either in the PHP (By setting some global variable and checking it before outputting the block. Poor form but it might work.) or in CSS. Let me know if any of these work for you.
Thanks,
Joe
Include the block in your layout instead:
<cms_page>
<reference name="left">
<block type="cms/block" name="leftSB1">
<action method="setBlockId"><id>leftSB1</id></action>
</block>
</reference>
</cms_page>
And then $this->getChildHtml('leftSB1') in your sidebar, if you're not including children automatically.
(and then remove it from the particular page as in the previous answer)

Resources