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

Confused about how templates pull in further templates
 
smokingdrum
Jr. Member
 
Total Posts:  4
Joined:  2008-05-13
 

I understand that XML defines the blocks which pulls in the template phtml pieces.

What I do not get is how some bits are being pulled in.

For example, I set the home page to use the 3 column layout. “3columns.phtml” seems to make sense except where it says getChildHtml(’right’)

But, where do ‘right’ and ‘left’ come from? I cannot find where it pulls this content from.

It sure would be helpful if someone could do a diagram of the heirachy of how an example page is pulled together. The Template Path hints is certainly useful, but it only shows phtml templates inside it, not where these getChild things are coming from.

Cheers

John

 
Magento Community Magento Community
Magento Community
Magento Community
 
NickL
Sr. Member
 
Avatar
Total Posts:  188
Joined:  2007-08-31
 

@smokingdrum

You were on the right path with looking at the XML files. If you browse through page.xml, you’ll see where right,left,content, and footer blocks are defined:

<block type="core/text_list" name="left" as="left"/>

            <
block type="core/messages" name="global_messages" as="global_messages"/>
            <
block type="core/messages" name="messages" as="messages"/>

            <
block type="core/text_list" name="content" as="content"/>

            <
block type="core/text_list" name="right" as="right"/>

Thats how they’re declared (someone correct me If im wrong).  Then… if you take a look at your page layout blocks, like “catalog.xml” you’ll see how those blocks are givin their child elements via their reference name set above.  Takethe layered navigation block for example:

<catalog_category_layered>
     <
reference name="root">
            <
action method="setTemplate"><template>page/2columns-right.phtml</template></action>
        </
reference>
         <
reference name="right">
        <
block type="catalog/layer_view" name="catalog.rightnav" template="catalog/layer/view.phtml"></block>
      </
reference>
        <
reference name="content">
            <
block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml"></block>
             </
reference>
        <
reference name="content">
        <
block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
             <
action method="addAttribute"><code>designer_1</code></action>
            </
block
            </
reference>
    </
catalog_category_layered>

Make more sense?  Let me know if you have further questions. I’ll be online for awhile.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tillebeck
Jr. Member
 
Total Posts:  24
Joined:  2008-03-03
 

Sorry. I still don’t get it.

Lets take an exmaple. On the mainpage with 3columns. Lets say I want to remove all bloks from RIGHT execpt the basket:
frontend/default/default/template/checkout/cart/sidebar.phtml

That will say remove the “compare”, the “callout” etc. How can I remove those blocks and still keep the basket?

In the page.xml it is all or nothing when removing anything from RIGHT.

BR. Anders

 
Magento Community Magento Community
Magento Community
Magento Community
 
doctorlogos
Sr. Member
 
Avatar
Total Posts:  178
Joined:  2008-05-06
 

You must see catalog.xml file. Take a look over <reference name="right">.
If you want to quit a block from this layout, simply uncomment the block with <!-- <block> -->
It works me, but please anyone, correct me if I´m wrong, or if there are a better way.
In this code, the block named “catalog.compare.sidebar” is disabled now.

<default>

        <!-- 
Mage_Catalog -->
        <
reference name="top.menu">
            <
block type="catalog/navigation" name="catalog.topnav" template="catalog/navigation/top.phtml"/>
        </
reference>
        <
reference name="left">
            <
block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml">
                <
action method="setImgSrc"><src>images/media/col_left_callout.jpg</src></action>
                <
action method="setImgAlt" translate="alt" module="catalog"><alt>Our customer service is available 24/7. Call us at (800DEMO-NUMBER.</alt></action>
                <
action method="setLinkUrl"><url>checkout/cart</url></action>
            </
block>
        </
reference>
        <
reference name="right">
            <!--<
block type="core/template" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>-->
            <
block type="core/template" name="right.permanent.callout" template="callouts/right_col.phtml"/>
        </
reference>
        <
reference name="footer_links">
            <
action method="addLink" translate="label title" module="catalog" ifconfig="catalog/seo/site_map"><label>Site Map</label><url helper="catalog/map/getCategoryUrl" /><title>Site Map</title></action>
        </
reference>

    </default>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Tillebeck
Jr. Member
 
Total Posts:  24
Joined:  2008-03-03
 

Thank you.
Now I understood the previous post. And I have managed to do the exclusions.

So far I have enabled the tempalte patchs so I can se the template for the different blocks. But from there and to figure out where those blocs are included… pew… it takes a while first time.

Is there a way to quickly figure out in wich xml-file the different blocks are included? Or will that just slowly become common knowledge when working with Magento.

BR. Anders

 
Magento Community Magento Community
Magento Community
Magento Community
 
tomislavbilic
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-17
Osijek, Croatia
 

Hello guys,

I wrote a tutorial how to add a new reference in Magento on our corporate blog. 

I hope someone will find it useful.

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Muhammed
Jr. Member
 
Avatar
Total Posts:  13
Joined:  2008-04-09
Istanbul, Turkey
 

you always say “its simple” on these template issues. but sorry guys; it-is-not!

i cant move mini search box from header to left.

when i changed the “header” value to “left” there is no more search box in the page.

<reference name="header">
            <
block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
        </
reference>

and i know, i must change something else, so it shows that it is not simple.

huh!

 
Magento Community Magento Community
Magento Community
Magento Community
 
miked2004
Sr. Member
 
Avatar
Total Posts:  214
Joined:  2007-12-13
Atlanta, Georgia
 

Hope this is not off topic: anyone ever changed a template from the controller?

in above example the template is set to “catalogsearch/form.mini.phtml” what if I wanted to change this from the controller if a condition was met. I have tried everything i can think of. and the worst part is that I think I have done this before but cant remember how I did it. I have tried getting the block and setting the template, adding a layout update, and none have worked or I have not done it correctly.

I just figured one way to do it from the blocks _prepareLayout function. just use

$this->setData('template''templatefilename');
)
This only seemed to work if the template was not set in the layout xml. probably need to use the layout update object to do it from the controller. Anyway this is one way to do it.
 
Magento Community Magento Community
Magento Community
Magento Community
 
Damodaran P
Jr. Member
 
Total Posts:  27
Joined:  2010-11-09
Kerala
 

Hi
The above posts are very useful.But I need to add a new menu bar in all pages for Stores. ie i need to display all stores available in the website at top of header.
(example http://www.magento-mall.com/). Please Help

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