Override Magento Template - magento

I'm making a module that needs to override the block/template for the top.phtml so I add in the layout of my module this code.
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<default translate="label" module="page">
<reference name="top.menu">
<action method="setTemplate"><template>navigationmenu/navigationMenu.phtml</template></action>
</reference>
</default>
</layout>
It doesn't work, but If I try to reference the header block it changes the template, I don't know if i have to set anything else in my xml.
Edit:
This is the structure in page.xml
<block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
<block type="page/html_header" name="header" as="header">
<block type="core/text_list" name="top.menu" as="topMenu" translate="label">
<label>Navigation Bar</label>
</block>
</block>
</block>
I realize I don't need the setTemplate because I need to use my custom Block
It is ok to put my reference under the default tag? Do I need to make another reference?
Also I'm running Magento EE 1.9.1.1 if that helps

Related

magento change block not working properly

I am using magento 1.7
on my product page I have added related product on right sidebar.
there are other block also displayed on sidebar these are
-related product
-recently viewed product
-mycart
-paypal logo
Now I want related product to get displayed after mycart and paypal logo, right now it is displayed on top of right bar
I have used before and after but that is not working.
These is my code
paypal.xml
<reference name="right">
<block type="paypal/logo" name="paypal.partner.right.logo" after="cart_sidebar" template="paypal/partner/logo.phtml"/>
</reference>
catalog.xml
<reference name="right">
<block type="catalog/product_list_related" name="catalog.product.related" after="paypal.partner.right.logo" template="catalog/product/list/related.phtml"/>
</reference>
checkout.xml
<reference name="right">
<block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml" before="-">
<action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/sidebar/default.phtml</template></action>
<action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/sidebar/default.phtml</template></action>
<action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/sidebar/default.phtml</template></action>
<block type="core/text_list" name="cart_sidebar.extra_actions" as="extra_actions" translate="label" module="checkout">
<label>Shopping Cart Sidebar Extra Actions</label>
</block>
</block>
how can I put mycart and paypal logo on top of right bar.
First you need to create or update your local.xml file IF you do not have a local.xml file you can create one in
app->frontend->[Package Name]->[Theme Name]->layout->local.xml
Once this is created you can copy exactly what I have in this post into that file for a start of how to use one.
DO ALL UPDATES THROUGH A LOCAL.XML file not through catalog.xml or checkout.xml !! This will make upgrades significantly easier later down the road. Additionally, you will be able to quickly see all changes you have made to your site in one file. This way I can see what you are actually updating.
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="right">
<!-- <action method="unsetChild"><alias>catalog.product.related</alias></action> -->
<block type="catalog/product_list_related" name="catalog.product.related" after="-" template="catalog/product/list/related.phtml"/>
</reference>
</default>
</layout>
If you end up with two try uncommenting my action method.. I can't remember if you have to declare it in separate reference or within there because I didn't test this but give it a try

How to remove std div in magento

I was trying to remove the "std div" from my magento home page, but unable to find the same any suggestion.
The div you are looking for is a page/html_wrapper block being added via the cms.xml layout file.
Here is the excerpt taken from app/design/frontend/base/default/layout/cms.xml:
<cms_page translate="label">
<label>CMS Pages (All)</label>
<reference name="content">
<block type="core/template" name="page_content_heading" template="cms/content_heading.phtml"/>
<block type="page/html_wrapper" name="cms.wrapper" translate="label">
<label>CMS Content Wrapper</label>
<action method="setElementClass"><value>std</value></action>
<block type="cms/page" name="cms_page"/>
</block>
</reference>
</cms_page>
So, there are a couple of ways to remove the div depending on how you develop your themes.
First option would be applicable if you use local.xml:
<cms_page>
<reference name="content">
<action method="unsetChild">
<alias>cms.wrapper</alias>
</action>
<block type="cms/page" name="cms_page"/>
</reference>
</cms_page>
Second option would be applicable if you copy the base layout files over:
Copy cms.xml from app/design/frontend/base/default/layout/cms.xml to app/design/frontend/your_package/your_theme/layout/cms.xml and edit the first layout snippet from above to the following:
<cms_page translate="label">
<label>CMS Pages (All)</label>
<reference name="content">
<block type="core/template" name="page_content_heading" template="cms/content_heading.phtml" />
<block type="cms/page" name="cms_page" />
</reference>
</cms_page>
This code helped me to remove "std" div from a single cms page,
put it to "Layout Update XML" section:
<reference name="content">
<action method="unsetChild">
<alias>cms.wrapper</alias>
</action>
<block type="cms/page" name="cms_page"/>
</reference>
EDIT:
Drew asked a question which makes me realize that your questions was how to remove the div (not just remove the class of the div). Ideally it's like any other "move" operation in layout XML, which means unsetting a parent-child relationship (in this case the one between the cms.wrapper and cms_page) and setting the child to another block (content):
<?xml version="1.0"?>
<layout>
<cms_page>
<reference name="content">
<action method="unsetChild">
<alias>cms.wrapper</alias>
</action>
<action method="insert">
<alias>cms_page</alias>
</action>
</reference>
</cms_page>
</layout>
My original response is below:
Drew has a lot of good information in his answer. I'll just point out that the block API has some nuance that can make the layout XML very clean.
In your local.xml:
<?xml version="1.0"?>
<layout>
<cms_page translate="label">
<reference name="cms.wrapper">
<action method="unsetElementClass" />
</reference>
</cms_page>
</layout>
Ref Mage_Page_Block_Html_Wrapper->_toHtml() and Varien_Object->__call()
Here is the solution you are finding :)
Put this xml code in Page -> Design -> Layout Update XML
<block type="page/html_wrapper" name="cms.wrapper" translate="label">
<label>CMS Content Wrapper</label>
<action method="setElementClass"><value>your_class_name</value></action>
<block type="cms/page" name="cms_page"/>
</block>
Cheers!
Saran

magento CE v1.6 toplinks in static block

I would like to have the topLinks within Magento CE 1.6 displayed within a static block. This is due to the fact that my site is running four different stores [multi-store - different domains] and need to have topLinks on only two stores, whilst using one template.
I did try to convert the php call [getChildHtml('topLinks'); ?>] into a block tag within the static block but was not successful. Have looked in depth at the xml for the template_links [made from varied xmls] but could not come to terms as how to just make a {{block}} within the static block to display the topLinks.
The call for the static block is in place, just need help achieving the topLinks within.
Any help will be appreciated.
With best regards
Fab
A fine tune of my question:
Basically I need to amend the page.xml
from
<block type="page/template_links" name="top.links" as="topLinks"/>
to
<layout>
<static_block_top_links>
<reference name="header">
<action method="unsetChild">
<name>topLinks</name>
</action>
<block type="cms/block" before="-" name="some_name" as="topLinks">
<action method="setBlockId">
<name>some_static_block</name>
</action>
</block>
</reference>
</static_block_top_links>
<STORE_store>
<update handle="static_block_top_links" />
</STORE_store>
<STORE_law>
<update handle="static_block_top_links" />
</STORE_law>
Use local.xml to implement your changes:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="header">
<!-- Unset original toplinks block -->
<action method="unsetChild">
<name>topLinks</name>
</action>
<!-- Add static block in place with same alias -->
<block type="cms/block" before="-" name="some_name" as="topLinks">
<action method="setBlockId">
<name>some_static_block</name>
</action>
</block>
</reference>
</default>
</layout>
Please note that 'some_name' can be anything except for 'top.links', as that would cause several things in core XML files to try and perform actions on your cms block.
In response to your edit, you can easily do it for only some stores like so:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<static_block_top_links>
<reference name="header">
<action method="unsetChild">
<name>topLinks</name>
</action>
<block type="cms/block" before="-" name="some_name" as="topLinks">
<action method="setBlockId">
<name>some_static_block</name>
</action>
</block>
</reference>
</static_block_top_links>
<STORE_myfirststore>
<update handle="static_block_top_links" />
</STORE_myfirststore>
<STORE_mysecondstore>
<update handle="static_block_top_links" />
</STORE_mysecondstore>
</layout>
Hello for anyone of you having a magento CE 1.6+ multi-store multi-domain and would like to remove the topLinks in general for certain stores, this is the correct method.
Create a local.xml in your app/design/frontend/default/yourtheme/layout/
Your local.xml should be like this
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<STORE_mystore1>
<reference name="header">
<action method="unsetChild">
<name>topLinks</name>
</action>
</reference>
</STORE_mystore1>
<STORE_mystore2>
<reference name="header">
<action method="unsetChild">
<name>topLinks</name>
</action>
</reference>
</STORE_mystore2>
</layout>
Replace the mystore1 and mystore2 with the code under Store View [Admin -> Manage Stores -> Store View Name -> Code]
Make sure that you encode the layout.xml in UTF-8
Upload the layout.xml in the app/design/frontend/default/yourtheme/layout/ folder.
Refresh the cache.
I would like to thank Daniel Sloof and Robert Popovic for their input.

Magento: Override only a part of a layout xml-File

I only want to change a part of the file checkout.xml (this file is in the core layout-folder). I create my own extension and link to my own layout-xml-File in my config.xml.
<layout>
<updates>
<checkout>
<file>mymodule_checkout.xml</file>
</checkout>
</updates>
</layout>
There are no problems, when i copy the whole file checkout.xml and save it as mymodule_checkout.xml. But I only want to override a little part of this big file between
<reference name="content">
and
</reference>
In this case, when i only write the parts that i needed, magento only read my file with this parts. So magento don't get the remaining parts of the original checkout.xml.
Is it possible to only change a part of a core layout xml-File without copying the whole file or change the core.
The Code of mymodule.xml looks like this:
<layout version="0.1.0">
<checkout_onepage_index translate="label">
<reference name="content">
<block type="checkout/onepage" name="checkout.onepage" template="checkout/onepage.phtml">
<block type="checkout/onepage_login" name="checkout.onepage.login" as="login" template="checkout/onepage/login.phtml">
<block type="page/html_wrapper" name="checkout.onepage.login.before" as="login_before" translate="label">
<label>Login/Registration Before</label>
<action method="setMayBeInvisible">
<value>1</value>
</action>
</block>
<block type="checkout/onepage_billing" name="checkout.onepage.billing" as="billing" template="checkout/onepage/billing.phtml"/>
<block type="checkout/onepage_shipping" name="checkout.onepage.shipping" as="shipping" template="checkout/onepage/shipping.phtml"/>
</block>
<block type="checkout/onepage_shipping_method" name="checkout.onepage.shipping_method" as="shipping_method" template="checkout/onepage/shipping_method.phtml">
<block type="checkout/onepage_shipping_method_available" name="checkout.onepage.shipping_method.available" as="available" template="checkout/onepage/shipping_method/available.phtml"/>
<block type="checkout/onepage_shipping_method_additional" name="checkout.onepage.shipping_method.additional" as="additional" template="checkout/onepage/shipping_method/additional.phtml"/>
</block>
<block type="checkout/onepage_payment" name="checkout.onepage.payment" as="payment" template="checkout/onepage/payment.phtml">
<block type="checkout/onepage_payment_methods" name="checkout.payment.methods" as="methods" template="checkout/onepage/payment/methods.phtml">
<action method="setMethodFormTemplate">
<method>purchaseorder</method>
<template>payment/form/purchaseorder.phtml</template>
</action>
</block>
</block>
<block type="checkout/onepage_review" name="checkout.onepage.review" as="review" template="checkout/onepage/review.phtml"/>
</block>
</reference>
</checkout_onepage_index>
</layout>
Thats the part I need. In this Case, magento take only this code not the remaining code of the core xml-file.
Absolutely, yes. Magento combines all your layout files into one, including files from fallback themes. Whatever is still relevant after it's processed all your files is what is used to produce your layout and as long as your xml is formatted correctly you can override any section from any .xml file - i.e. just 'cause it's called page.xml doesn't mean you can't override it in foobarbaz.xml.
It's more than likely your problem lies with your XML, can you post the contents of mymodule_checkout.xml so I can figure out what you're trying to do and hopefully provide you with a working replacement?

Customizing Magento Sidebar

How can I edit or add blocks on the sidebar in magento
If you have a custom layout, you could use that to overwrite the block/"sub-block" by using a reference
<reference name="right">
<!-- Your customisation here -->
</reference>
http://www.magentocommerce.com/design_guide/articles/intro-to-layouts
specifically you might like to look at this image:
http://www.magentocommerce.com/images/uploads/term_reference.gif
Go to app/design/frontend/default/[yourtheme]/layout location and create page.xml by copying it from the base/default/layout folder.
Search for:
<block type="core/text_list" name="right" as="right" translate="label">
<label>Right Column</label>
</block>
And change it to:
<block type="core/text_list" name="right" as="right" translate="label">
<label>Right Column</label>
<block type="core/template" template="pth/to/your/layout.phtml"/>
</block>

Resources