Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento layout override!

Tags:

php

magento

I'm kind of new to the Magento, so forgive me for my stupid question! As I understand the whole concept of Magento is base on overriding the basic components that's are available with in the Magento.

So based on my understanding I've decided to update the layout of onepage checkout in Magento. I've created my own layout and in the config file set that my layout updates the checkout module layout. But the problem is it's actually does not update the base layout, it replaces it self with base layout! Should it be act like this or am I wrong?!

like image 404
Farid Avatar asked May 29 '10 07:05

Farid


People also ask

How do I override layout XML in Magento 2?

* To override page layout files, use the page_layout directory name instead of layout . * Remember to always name your new layout files with the same name as the file that you wish to override.

How do I override a Magento 2 template?

More specifically, in Magento 2, any module's or parent theme's layout, template, or web can be overridden with ease just by placing it in <theme_dir>/<Vendor>_<Module>/path/to/file . For instance, for the Magento_Theme module, you can place your template in <theme_dir>/Magento_Theme/templates/html/header.

How do I override a base file in Magento 2?

The solution was simple, just create the file in app/design/frontend/[VendorName]/[theme]/Magento_Tax/templates/pricing/adjustment. phtml. Show activity on this post. app/design/frontend/[VendorName]/[theme]/Magento_Tax/templates/pricing/adjustment.


1 Answers

In fact, the node in your config.xml file doesn't do an "update". As a matter of fact, I think you have done that in your config.xml :

<config>
    <frontend>
        <layout>
             <updates>
                  <checkout>
                        <file>mylayout.xml</file>
                  </checkout>
             </updates>
        </layout>
    </frontend>
</config>

and you have done your modifications in mylayout.xml.

In fact, you have to do :

<config>
    <frontend>
        <layout>
             <updates>
                  <mymodule>
                        <file>mylayout.xml</file>
                  </mymodule>
             </updates>
        </layout>
    </frontend>
</config>

And then, in mylayout.xml :

<checkout_cart_index> <!-- this corresponds to the section where you want to add your block (or modify an existing block -->
       <reference name="content">
            <reference name="checkout.cart">
                <block type="mymodule/myblock" name="checkout.mymodule.myblock"></block>
            </reference>
        </reference>
</checkout_cart_index>

By looking at my code and comparing the files to each other, you will understand better how it works.

In fact, don't forget that all xml files are concatenated in magento. So that, all nodes in all config files, respecting the same order, will be concataneted.

For example, in our case, the config.xml files of magento will be concatenated, and the result is ONE file containing :

<config>
<!-- some nodes... -->
<!-- some nodes... -->
<!-- some nodes... -->
    <frontend>
        <layout>
             <updates>
                  <mymodule>
                        <file>mylayout.xml</file>
                  </mymodule>
                  <checkout> <!-- this is the node from the config.xml of the Checkout Module-->
                        <file>checkout.xml</file>
                  </checkout>
                  <!-- some layout updates nodes from other config files... -->
             </updates>
        </layout>
    </frontend>
<!-- some nodes... -->
<!-- some nodes... -->
</config>

If you had replaced <mymodule> by <checkout> the resulting file would have looked :

<config>
<!-- some nodes... -->
<!-- some nodes... -->
<!-- some nodes... -->
    <frontend>
        <layout>
             <updates>
                  <checkout>
                        <file>mylayout.xml</file>
                  </checkout>
                  <!-- some layout updates nodes from other config files... -->
             </updates>
        </layout>
    </frontend>
<!-- some nodes... -->
<!-- some nodes... -->
</config>

Note the mylayout.xml. This is the reason why the original layout file is completely replaced by your own layout :)

Hope that's clear, in french it would have been easier for me to explain ;)

Hugues.

like image 187
liquidity Avatar answered Sep 30 '22 18:09

liquidity