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

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?

Related

I cannot find where the static blocks are stacking up from on my home page

<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 type="core/template" name="pageHeader" template="page/html/topcontainer.phtml">
<block type="core/template" name="page.header" template="page/html/page_header.phtml"/>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>
</block>
</block>
This block lines up my entire home page. I need to add another block in to this list. This is read from CMS blocks in Admin panel. How can I find the source.
Use this code you will be able to read from CMS blocks in Admin panel with name contact.
<reference name="left">
<block type="cms/block" name="contact" before="-">
<action method="setBlockId"><block_id>contact</block_id></action>
</block>
</reference>

Override Magento Template

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

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 Block Positioning Never Works

Hello I always seem to have problems positions blocks.
Please see the website I am working on: http://www.hemptationz.com
I want the blocks on the left sidebar to appear in this order:
Facebook Block (callouts/facebook.pthml)
Currency Block (directory/currency.phtml)
Product Categories Block (vertnav/left.phtml)
Information Links Block (callouts/left_col.phtml)
This is the code I have in the XML layout files:
Catalog.xml
<reference name="left">
<block type="core/template" name="facebook" template="callouts/facebook.phtml" after="currency" />
<block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml" after="catalog.vertnav" />
</reference>
vertnav.xml
<reference name="left">
<block type="vertnav/navigation" name="catalog.vertnav" template="vertnav/left.phtml" before="left.permanent.callout" />
</reference>
directory.xml
<layout version="0.1.0">
<!--
Category default layout
-->
<default>
<reference name="head">
<block type="core/template" name="optional_zip_countries" as="optional_zip_countries" template="directory/js/optional_zip_countries.phtml" />
</reference>
</default>
<catalog_category_default>
<reference name="left">
<block type="directory/currency" name="currency" before="facebook" template="directory/currency.phtml"/>
</reference>
</catalog_category_default>
<!--
Category layered navigation layout
-->
<catalog_category_layered>
<reference name="left">
<block type="directory/currency" name="currency" before="facebook" template="directory/currency.phtml"/>
</reference>
</catalog_category_layered>
<!--
Catalog Search layout
-->
<catalogsearch_advanced_index>
<reference name="left">
<block type="directory/currency" name="right_currency" before="facebook" template="directory/currency.phtml"/>
</reference>
</catalogsearch_advanced_index>
<catalogsearch_result_index>
<reference name="left">
<block type="directory/currency" name="currency" before="facebook" template="directory/currency.phtml"/>
</reference>
</catalogsearch_result_index>
<catalogsearch_advanced_result>
<reference name="right">
<block type="directory/currency" name="right_currency" before="facebook" template="directory/currency.phtml"/>
</reference>
</catalogsearch_advanced_result>
</layout>
Thanks hope you can help me.
The before and after attributes are limited in scope. They can only influence
The order of blocks within a particular sub-block when that sub-block is a core/test_list or other block that automatically renders sorted children.
You've not given enough context around how you're using the attributes in your question to give you specific advice, but I don't think you can do what you think you can with the feature. Be more explicit in your question and provide code example, along with "I expected foo, I got bar" style context, and will help you.
You want this order:
1. Facebook
2. Currency
3. Vertical Navigation
4. Information Links
but in your layout you have specified that facebook is after currency. If you want something to show first you have to use before="-" (in facebook link), then use after="facebook" for currency, after="currency" for catalog.vertnav and use after="-" for left.permanent.callout to position it on the bottom.

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