简体   繁体   中英

How magento works phtml/xml?

I'm starting in magento and want to know how some things work.

Eg sometimes, when searching for a , i find some code in magento like this:

  <? php echo $ this-> getChildChildHtml ('container2','', true, true)?>

I managed to identify that this code above shows exactly the that I want to work, but I know that this line only draws the , like to know the path to get to the and power to change it, knowing that this expedite my job.

Inside magento urls you have a path like: module / controller / action. Almost every module has a layout xml file in the base/default theme. The nodes from layout are composed of

module's frontend name (from module etc/config.xml file) "_" controller "_" action

so a node from checkout.xml would be like "checkout_cart_index" . Inside these nodes from layout xml you have references to parts of the template <reference name="content"> this is a big block from page.xml defined as shown from one of the page phtmls (1column, 2columns-left, 2columns-right, 3columns, print ...):

<block type="core/text_list" name="content" as="content" translate="label"> <label>Main Content Area</label> </block> and from the phtml:

<?php echo $this->getChildHtml('content') ?>

Now going back to checkout.xml file you can see the child blocks for that reference (keep in mind this is also a block), example:

<block type="checkout/cart" name="checkout.cart">...</block>

To see a list of methods you should look at the class the block is instantiating, for example if you see in the xml a block that has type="checkout/cart" that means you should look for the etc/config.xml that has:

<blocks> <checkout> <class>Mage_Checkout_Block</class> </checkout> </blocks>

this is actually from the Mage_Checkout module so checkout/cart translates to Mage_Checkout_Block_Cart

Most blocks in Magento extend Mage_Core_Block_Template which has a couple of interesting methods such as setTemplate and _toHtml.

So for $this->getChildChildHtml('container2','', true, true) you would have to look inside the layout xml file where your block is defined, there you should see it's children and also the container2 child. I found a container2 inside catalog.xml

<block type="core/template_facade" name="product.info.container2" as="container2"> <action method="setDataByKey"><key>alias_in_layout</key><value>container2</value></action> <action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action> <action method="append"><block>product.info.options.wrapper</block></action> <action method="append"><block>product.info.options.wrapper.bottom</block></action> </block>

The 'as' value is used instead of the name for future reference of the block. This is the class of this block Mage_Core_Block_Template_Facade

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM