The method of getChildHtml

The php method getChildHtml(’right’) does not refer in any way to right.phtml. “right” is simply an identifier in order for templates and the layout file to interact with each other in order to structure and bring content to the page. Remember, changing the layouts of a page in Magento means no longer relying on manual XHTML inclusion in one large structural block template such as col_right.phtml. Think of it this way:

There are now three parts to modifying page layout. One is the structural templates, two, content templates, and three is what Magento calls “layouts”.
Structure templates are templates that simply creates the structural layout of a page - such template exists only to designate real estate for content inclusion. A sample structural template would look something like the following:

< div  class= "header" > <? = $this -> getChildHtml ( 'header' ) ?> </ div >
<
div  class= "col-left" > <? = $this -> getChildHtml ( 'left' ) ?> </ div >
<
div  class= "col-main" > <? = $this -> getChildHtml ( 'content' ) ?> </ div >
<
div  class= "col-right" > <? = $this -> getChildHtml ( 'right' ) ?> </ div >
<
div  class= "footer" > <? = $this -> getChildHtml ( 'footer' ) ?> </ div >

You can see how the XHTML used in a skeleton template is only there to build structural.

A layout arranges the content blocks such as product tags, category listing, mini cart, mini wishlist..etc, then delivers it to the structural block to be parsed in the assigned order.
All this in human language is basically “Grab all the mini cart, grab the compare products, grab the poll and the grab the newsletter sign up box, and put all this inside the <div class="col-right">." The one that orders this whole operation, is the layout . Each of the mini-cart, compare products..etc are the content blocks. The <div class="col-right"></div> is the structural block.

The layout only knows where to include all the content blocks via the getChildHtml() method used in the structural template. Using the assigned identifier called “right” as in getChildHtml(’right’), the layout knows where to put all the content blocks it gathered - inside the <div class="col-right"></div>

For each design theme, you have a default layout, and the subsequent layout updates. The default, is what sets the default layout for the whole store, and the layout updates is the layout that modifies(updates) the default layout per store page. So if the default layout says, use 3 columns, but you want your product info page to use 2 columns only, you’d update the <catalog_product_view> “handle” inside main.xml to reflect this. Main.xml is pretty well commented - read through it carefully with open eyes and you’ll see what’s happening there. Also the Magento team is here to assist you with any questions - 24 hours a day 7 days a week - (we are born with each finger stuck to a keyboard...and we have mutating tentacles to accommodate all the other keys we can’t cover with the 10 fingers)

O.K.!! we got the concept over with. Now let’s get our hands dirty, stinky, muddy, cracking, invigorated, satisfied...happy.
Comment out the following codes from main.xml

< block type = "core/template"  name = "catalog.compare.sidebar"  template = "catalog/product/compare/sidebar.phtml" />

 

< reference name = "right" >
           <
block type = "newsletter/subscribe"  name = "right.newsletter"  template = "newsletter/subscribe.phtml" />
        </
reference >
< reference name = "right" >
            <
block type = "poll/activePoll"  name = "right.poll" >
                <
action method = "setPollTemplate" >< template > poll / active . phtml </ template >< type > poll </ type ></ action >
                <
action method = "setPollTemplate" >< template > poll / result . phtml </ template >< type > results </ type ></ action >
            </
block >
        </
reference >

Now reload the page. That’s all-

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章