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

Can anyone tell me what these layout xml files mean? 
 
anthonyfojas
Member
 
Total Posts:  33
Joined:  2008-08-19
 

I’ve been looking around for any kind of documentation about the tags and attributes in the file, but haven’t found anything that specifically says what they mean.

I’ve read through the following pages as well as some others, but I am still lost.
http://www.magentocommerce.com/wiki/how-to/designing/designing-for-magento#using_xml_to_change_layout
http://www.magentocommerce.com/boards/viewthread/1438/

Is there some secret location for the documentation that explains the catalog.xml file?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

alas, documentation is rather sadly lacking (hopefully to be worked on in the future).

Learning magento is a slower process because of this....

Anyway, the layout xml files control just that: layout

They tell if to add items in left, content or right, header or footer area (etc)...they can run methods inside of Blocks (such as header and footer links - they are added via a layout xml file...)

It’s a lot to get into since the layout xml files do a lot of stuff.

To get started, trying checking out the designers guide and seeing their examples / small tutorial to get started. Then try messing around with them and see what happens.
Helps to know PHP also…

Oh, and if you see <block type="something/somethingelse"… /> that points to app/code/core/mage/something/block/somethingelse(.php)

Sorry I don’t have time for a comprehensive answer

 
Magento Community Magento Community
Magento Community
Magento Community
 
anthonyfojas
Member
 
Total Posts:  33
Joined:  2008-08-19
 

Thanks for the info.

What I’m really having difficulty understanding is how these translate to what appears in the phtml files.  For example, if I need to get the breadcrumbs (type=page/html_breadcrumbs) into the item listing page (template/catalog/product/list.phtml), how do I do that?  In the template/page/1column.phtml file there is <?php echo $this->getChildHtml('breadcrumbs') ?>, but this doesnt work in the list.phtml file.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 
anthonyfojas - 19 August 2008 12:16 PM

Thanks for the info.

What I’m really having difficulty understanding is how these translate to what appears in the phtml files.  For example, if I need to get the breadcrumbs (type=page/html_breadcrumbs) into the item listing page (template/catalog/product/list.phtml), how do I do that?  In the template/page/1column.phtml file there is <?php echo $this->getChildHtml('breadcrumbs') ?>, but this doesnt work in the list.phtml file.

You will need to find the reference to the breadcrumbs box in an xml file, and then copy and paste it (or cut it) into the xml file that handles the item listing page. Then you can use that $this->getChildHtml(’breadcrumbs’); in list.phtml

The reference will be something like

<block type="page/html_breadcrumbs" name"something" as="breadcrumbs" template="template/catalog/product/list.phtml" />
 
Magento Community Magento Community
Magento Community
Magento Community
 
anthonyfojas
Member
 
Total Posts:  33
Joined:  2008-08-19
 

Thanks again, but I still don’t understand what I just did.

I added this to the catalog.xml file (I removed the template attribute because the code you posted was including the list.phtml into itself).

<block type="page/html_breadcrumbs"  name="something" as="breadcrumbs"  />

This just makes the following 2 lines do the same thing in the list.phtml file. 

<?php echo $this->getLayout()->createBlock('page/html_breadcrumbs')->setBlockId('breadcrumbs')->toHtml()  ?> 
<?php 
echo $this->getChildHtml('breadcrumbs'?>

The above just displays blank blocks because the $crumbs variable isn’t being passed into the template or is not being set properly.  What am I missing that allows the page.xml file to pass in the $crumbs array?

I tried adding a getCrumbs method into the Mage_Page_Block_Html_Breadcrumbs class to get the protected _crumbs array straight from the object, but it just returns a null.

Any advice? Sorry if this is getting a little off topic.

 
Magento Community Magento Community
Magento Community
Magento Community
 
anthonyfojas
Member
 
Total Posts:  33
Joined:  2008-08-19
 

I realized that there is another class in the catalog/blocks/breadcrumbs.php that seems to be the one that adds the breadcrumbs into the other class.  Where does that guy get loaded in?  None of the xml files make reference to catalog/breadcrumbs.

Am I the only one that finds Magento to be overly complicated?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

OK i was just looking into this.

1) breadcrumbs.phtml will always be the template that outputs breadcrumbs

2) Breadcrumbs is on every page because it is set in page.xml, which controls the base layout for everything. You sometimes don’t see the breadcrumbs (for instance, on your cart page) because the crumbs array is sometimes left empty, and the template only outputs stuff if the array is NOT empty.

You might be then asking yourself “well then where are the breadcrumbs being set ?!”
This took me some time to find.
The Block php (breadcrumbs.php) file controlling the breadcrumbs.phtml template has (like many items of this variety) only one notable function - “addCrumbs” - this function is only used to add to the breadcrumb list. The actual breadcrumbs used are set elsewhere

A lot of times this is set in one of the XML files. It’s where I spent most of my time looking also!  In fact, IDK why they didn’t use the XML files in this case. Perhaps there was a limitation or something that needed to be set that the XML alone couldn’t handle (most likely I think now that I look at the code some more)

Anyway, I finally found the missing piece (and probably the source of your confusion)

3) app/code/core/mage/Catalog/block/breadcrumbs.php
This file is whats setting the breadcrumbs for your catalog pages. (using the addCrumb function)!!
You can go to it and see exactly how it is doing it - it’s basically bypassing the use of XML (in fact, all the XML layouts are icing on the cake in magento - you could technically not use XML at all, just use PHP functions...)

If you check out app\code\core\Mage\Catalog\Block\Product\view.php you will see one of the first things it does is create the catalog/breadcrumbs block! (in it’s own _prepareLayout function)

$this->getLayout()->createBlock('catalog/breadcrumbs');

so the view.php file is where you are looking for - it is the final piece that shows the breadcrumbs @ product listings
The list php/phtml is actually wrapped inside of view.php/phtml, so the listings pages will all have the breadcrumbs

edit: you are def not the only one who things magneto is very complicated rasberry

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