The use of the Magento function getchildhtml () and getchildchildhtml ()

Source: Internet
Author: User
Tags vars

  1. Getchildhtml (' a ') //Load as= ' a ' block
  2. Getchildhtml ("); //Load all child blocks
  3. getchildchildhtml (' container1 ', ' B ', true, true); //Loading sub-block Container1 and his sub-block (as= ' B ');
  4. getchildchildhtml (' container1 ', ', true, true); //Load sub block Container1, and all sub-blocks below
      1. <?php echo $this-getchildchildhtml ( ' container1 ', ', true, True)?>
      2. <?php echo $this-getchildchildhtml ( ' container2 ', ', true, True)?> /c9>
  5. In the Magento default configuration, the HTML output starts with a block named "Root" (in fact, because the block has an output property "Efish Note: Any block that has an output property is a top-level block, In the case of multiple top-level blocks, the Magento will output HTML in the order in which the blocks are defined. We've covered the "root" block template

    template="../../../../../code/local/Alanstormdotcom/Helloworld/simple_page.phtml"
    The find path to the template file is the root of the current theme (theme), Magento the default settings here
    app/design/frontend/base/default

    Add content to a page

    So far, our pages have been more boring and nothing. Let's add some meaningful content to the page. Modify Local.xml as follows
    <reference name="root">
    <block type="page/html" name="root" template="../../../../../code/local/Alanstormdotcom/Helloworld/simple_page.phtml">
    <block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml"/>
    </block>
    </reference>

    We nested a block of "customer_form_register" inside the "root" block. This block is Magento, which contains a user registration form. We embed this block inside, so we can use the content of this block in the template file. Use the following method to modify the simple_page.phtml
    <body>
    <?PHP echo $this->getChildHtml(‘customer_form_register‘); ?>
    </body>

    The "getchildhtml" parameter here is the name of the block to be introduced, which is very convenient to use. Empty the Magento cache, refresh the Hello World page, and you should see the user registration form on the red background. Magento also has a block called "top.links", let's add it in. Modify Simple_page.html
    <body>
    <?php echo $this->getChildHtml(‘top.links‘); ?>
    <?php echo $this->getChildHtml(‘customer_form_register‘); ?>
    </body>

    Refresh the page and you'll see that the

    We modified the Local.xml file as follows
    <reference name="root">
    <block type="page/html" name="root" template="../../../../../code/local/Alanstormdotcom/Helloworld/simple_page.phtml">
    <block type="page/template_links" name="top.links"/>
    <block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml"/>
    </block>
    </reference>

    Empty the Magento cache, refresh the page, and you'll see a row of links showing up. Efish Note: If you're careful, you'll find that the "top.links" block has no template attribute, because the default template must be defined in this block's class
    protected function _construct()
    {
    $this->setTemplate(‘page/template/links.phtml‘);
    }

The use of the Magento function getchildhtml () and getchildchildhtml ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.