tags:

views:

51

answers:

3

Here is what I think about Magento (plz correct me if I am wrong )

1)Each module has its own layout.xml stored in /interface/theme/layouts/ folder. 2)Magento loads all these layouts for current theme and creates a big xml file.

Now what I am confused at .

a)If magento loads /default/default/ (interface & theme) then why all the templates & layouts are inside base/default/ ??

b)what if I create my module name “page” inside my namespace “Jason” i.e Jason_Page , now what will happen to blocks in layout files which are named

c)Since all the layouts are loaded and merged into one big xml file , then what happen to all those reference blocks which have same name attribute and are inside “Default” handle tag ? e.g

d)what is Local.xml layout for and its use ?? e)wats the relation ship between a module name foo , and its layout name foo.xml ? What will happen to layout.xml if two modules with same name exist in diff namespace ?

Thanks in advance .

A: 

1) Each module can choose to define layout files that go into the /interface/theme/layouts/ folder. You can accomplish this by specifying the layouts in your module's config.xml file like this:

<frontend>
    <layout>
        <updates>
            <jason_page>
                <file>jasonpage.xml</file>
            </jason_page>
        </updates>
    </layout>
</frontend>

2) Yes.

a) Magento's interface is built using descendency. Templates and layouts are first taken from your chosen interface and theme, and if not found there, will be taken from base. This allows you to define only those things that change from the base when creating a new them.

b) If you create a new module with blocks, you will specify the classpath for those blocks in your config.xml:

<global>
    <blocks>
        <jason_page>
            <class>Jason_Page_Block</class>
        </jason_page>
    </blocks>
</global>

This will define the tag jason_page to refer to your blocks. Then, when defining a layout, you will reference your blocks as:

<block type='jason_page/blockname' as='blockname' name='blockname' />

And your blocks will be named as: Jason_Page_Block_Blockname in /app/code/local/Jason/Page/Block/Blockname.php

c) Each time you use a <reference> tag and add some child blocks, they are added to the large tree as you say. Make sure to use different name/as tags for the blocks, and you'll be fine. If the name is identical, you will probably cause errors.

d) local.xml (in app/etc) defines some configuration parameters for your site, such as database connection information and encryption keys. it doesn't have to do with layouts.

d part 2) Since you define your layout files, including their names, it's up to you to not cause collisions. Choosing a module name more unique than Page would go far here. If you do have a module with the same name as a default module (e.g. Page), prefix the file with your namespace when declaring it in your config.xml file.

Hope that helps!

Thanks, Joe

Joseph Mastey
@Joseph MasteyI was looking for these ans for a long time. thank you so much dear :)Only thing which remain is why reference tag not working for me ?I just created my block and template and Inside my module layout I tried to use reference name="right" tag to enclose my blocks but it didnt worked ???
jason bourne
@user197992 If it's still not working, try posting some of the code from your config.xml and layout.xml just to make sure. If my answer fixed it, make sure to click the checkmark next to it to mark it as correct :)
Joseph Mastey
@Joseph Mastey reference tag is also working , also I have marked it thanks once again.
jason bourne
A: 

Just to add to Joe's answer, you can have interface/theme/layout/local.xml file, and it will be loaded after all other core and module layout XML files.

Use this file for local theme customizations.

Unirgy
A: 

I just recently wrote a post about how to use static blocks. Here is the meat of it:

Step One: Create Static Block in Your Magento Admin

Magento Admin Panel—>Static Blocks—>Add New Block

1) Name your Static Block, in this case Custom footer Links

2) Label the Identifier (This is the link you will use to call the block later) in this case, custom-footer-links

3) Choose what store view you would like it to render in

4) Set Status to Enabled

2)Now for the fun part! Add your navigation links to the block. Make sure to use to make them match your sites color and theme.

Step Two: Inserting Code to Call the Static Block

This part is going to require you to FTP into your Magento site and modify footer.phtml app—>design—>frontend—->default—>(your template)—>template—>page—>footer.phtml

Find where in the footer you want your navigation links to display and insert: getLayout()->createBlock(‘cms/block’)->setBlockId(‘custom-footer-links’)->toHtml(); ?>

Now most of the time the Static block should display just fine but in some cases you are going to have do some extra steps to have the block display.

1) Instead of inserting: getLayout()->createBlock(‘cms/block’)->setBlockId(‘custom-footer-links’)->toHtml(); ?>

Use:

custom-footer-links

2)Modify catalog.xml app—>design—>frontend—>default—>f002—>layout—>catalog.xml

Add under

custom-footer-links

I have more tips at my blog http://www.interactone.com/ and if you found this information helpful don't forget to vote me up!

Thomas