Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Where can i find an introduction about used design patterns in magento core? 
 
mojovski
Jr. Member
 
Total Posts:  6
Joined:  2009-01-24
 

Hello guys,
today i was trying to create my first interface and theme but i ran into a huge problem:
i do not understand how the interaction between the layout files and the template files works. (what are blocks exactly? when is the file parsed? when are the templates called?)
can somebody give me a hint on some kind of blog-link or something similar, where the core design of the system is described?
I found many introductions for users (using the gui...) but this is not what i am actually looking for.
i am a developer and would like to understand the way magento works internally in order to be able to extend it (by now just the templates, later also writing some extensions).
i am used to the (genius) structure in ruby on rails and the magento style with 1k xml configuration files is some kind of strange… but well.

thanks a lot for every hint!

regards
eugen

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rich Cleverley
Sr. Member
 
Avatar
Total Posts:  285
Joined:  2009-01-20
 

Hi Eugen,

This is just the basics so feel free to ask other questions as you need.

Basically blocks are VIews (as in the MVC View).  So, in teh layout xml files when there is a block defined, teh block type is the path to the block code in magento which can either be core or your own extension code.

A quick example is this.

<block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/left.phtml"/>

Taken from layout/catalog.xml

the block type “catalog/navigation” refers to the php file app/code/core/Mage/Catalog/Block/Navigation.php

The template catalog/navuigation/left.phtml will use this php file for the methods that are called in it.

Now, as for the layout of the xml files.

If we take this from catalog.xml again:

<block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml">
            <
block type="catalog/navigation" name="main_categories.leftnav"  template="catalog/navigation/cats_left.phtml"/>

so, here we have two blocks.  One is core/template and one is catalog/navigation.

Basically the catalog/navigation is a block that is called from with in the core/template one, or more correctly, it is a block that is referenced in the parent template (callouts/left_col.phtml).  If you look in this file you will see

<?php echo $this->getChildHtml('main_categories.leftnav')?>

What is happening here is we are saying we want the block that we have given the name ‘main_categories.leftnav.  I’m sure you’ve already spotted that the catalog.navigation block we have in catalog.xml above is called ‘main_categories.leftnav’.  So, this is the template and block that is rendered to the browser.

Like I say, this is a very basic explanation of the layout xml files.  Personally I think they are brilliant once you get into them

Hope this helps!

Rich

 
Magento Community Magento Community
Magento Community
Magento Community
 
mojovski
Jr. Member
 
Total Posts:  6
Joined:  2009-01-24
 

Hello Rich,
thanks a lot for the explanation. It made some points clearer.
I explored the structure of magento today for about 4 hours and understood some aspects, but one important one is still unclear. Maybe you can help me out a little bit.

When I define a block in page.xml

<block type="core/text_list" name="left" as="left" translate="label">
                <
label>Left Column</label>
</
block>
how does the system decides which modules can access this block?
I saw for example (by invoking grep -R -I “<reference name=\"left\"” . )
that some modules reference that block. 
Are all modules loaded at the same time? So the system lets all of them reference the “left” block and put content into it?
if so, why not all module layouts, which appear to use
<reference name="left"
can be seen in the left column?

This would mean, i need to copy the existing checkout.xml and remove the reference to my specific block. right?

thanks a lot again!
regards
Eugen

PS: Is there a syntax reference with explanations for the xml definition files? smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top