標籤:使用者註冊 href net custom frontend tag protect blank sim
- getChildHtml(‘a‘) //載入as=‘a’的block
- getChildHtml(‘‘); //載入所有的子block
- getChildChildHtml (‘container1‘ , ‘b‘ , true , true); //載入子block container1以及他的子block(as=‘b‘);
- getChildChildHtml (‘container1‘ , ‘‘ , true , true); //載入子block container1,以及下面的所有子block
- <?php echo $this -> getChildChildHtml ( ‘container1‘ , ‘‘ , true , true ) ?>
- <?php echo $this -> getChildChildHtml ( ‘container2‘ , ‘‘ , true , true ) ?>
-
在Magento預設的配置下,HTML輸出是從名為“root”的塊開始(其實是因為這個塊 擁有output屬性【EFISH註:任何一個擁有output屬性的塊都是頂層塊,在擁有多個頂層塊的情況下Magento將按照塊定義的先後順序輸出 HTML】)。我們覆蓋了“root”塊的模板
template="../../../../../code/local/Alanstormdotcom/Helloworld/simple_page.phtml"
模板檔案的尋找路徑是當前主題(theme)的根目錄,Magento預設設定時這裡
app/design/frontend/base/default
為頁面加入內容
到目前為止,我們的頁面都比較無聊,啥也沒有。我們來為頁面加點有意義的內容。修改 local.xml如下
<helloworld_index_index>
<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>
</helloworld_index_index>
我們在“root”塊裡面嵌套了一個塊“customer_form_register”。這個塊是Magento本來就有的,包含了一張使用者註冊表單。 我們把這個塊嵌套進來,那麼我們在模板檔案裡面就能用這個塊的內容。使用方法如下,修改simple_page.phtml
<body>
<?PHP echo $this->getChildHtml(‘customer_form_register‘); ?>
</body>
這裡“getChildHtml”的參數就是要引入的塊的名字,使用起來相當方便。清空Magento緩衝,重新整理hello world頁面,你應該在紅色背景上看到使用者註冊表單。Magento還有一個塊,叫做“top.links”,讓我們把它也加進來。修改 simple_page.html
<body>
<h1>Links</h1>
<?php echo $this->getChildHtml(‘top.links‘); ?>
<?php echo $this->getChildHtml(‘customer_form_register‘); ?>
</body>
重新整理頁面,你會發現<h1>Links</h1>顯示出來了,但是“top.links”什麼都沒有顯示。那是因為我們並沒有把 這個塊引入到local.xml,所以Magento找不到這個塊。“getChildHtml”的參數一定要是當前頁面的布局檔案中聲明過的塊。這樣的 話Magento就可以只執行個體化需要用到的塊,節省了資源,我們也可以根據需要為塊設定不同的模板檔案。
我們修改local.xml檔案如下
<helloworld_index_index>
<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>
</helloworld_index_index>
清空Magento緩衝,重新整理頁面,你會看到一排連結顯示出來了。【EFISH註:如果你細心一點的話你會發現“top.links”塊沒有template屬 性,那是因為這個塊的類中一定定義了預設的模板
protected function _construct()
{
$this->setTemplate(‘page/template/links.phtml‘);
}
magento函數getChildHtml() 與getChildChildHtml() 的用法