2016-12-16 30 views
0

我想知道如何找到某個頁面的塊類型示例:主頁。獲取頁面的塊類型Magento

我在我的網頁有問題,我想展示一些塊,在XML中,我宣佈我的塊<cms_index_index>(local.xml中),但如果我把它放在它出現在<reference name="head">,如果<reference name="content"><reference name="content">它不行 。在我看來,塊的類型不好。

XML:

<cms_index_index> 
     <reference name="root"> 
      <block type="core/template" name="seconnecter_test" template="customer/form/test-seconnecter.phtml"/> 
     </reference> 
</cms_index_index> 
在網頁1column-full.phtml我把它叫做這樣

<?php echo $this->getChildHtml('seconnecter_test');?> 
+0

解決方案:$ this-> getBlockHtml('name_block'); – Prince

回答

0

您可以使用

<reference name="root"> 
    <block type="core/template" name="seconnecter_test" output="toHtml" template="customer/form/test-seconnecter.phtml"/> 
</reference> 
+0

使用output =「toHtml」將塊作爲輸出塊,只有輸出塊自動呈現。 –

+0

我測試了它的工作原理,但它顯示了頁面底部的區塊,而我想在一些區塊之後在中間顯示它,這就是爲什麼我想使用參考名稱=「root」和get phtml中的get子項。 – Prince

+0

您可以在塊定義中使用before/after屬性。 –

0

當你給<reference name="content">他們的塊類型是core/text_list。此塊類型自動輸出其內容,您不需要使用getchildhtml()

在你local.xml中

<?xml version="1.0"?> 
<layout version="0.1.0"> 
    <cms_index_index> 
    <reference name="content"> 
     <block type="core/template" name="seconnecter_test" before="_" template="customer/form/test-seconnecter.phtml"/> 
    </reference> 
    </cms_index_index> 
</layout> 

發生在正確的位置的模板文件,塊將呈現在內容的頂部。

或者試試這個從管理面板去cms->pages->homepage。在佈局更新xml中添加以下設計部分

<reference name="content"> 
     <block type="core/template" name="seconnecter_test" before="_" template="customer/form/test-seconnecter.phtml"/> 
    </reference> 

刷新緩存。

+0

我測試過了,它不起作用!我使用了Suman Singh的解決方案,但是它顯示了底部的塊,而我想在一些塊之後在中間顯示它,這就是爲什麼我想使用參考名稱=「root」和phtml中的get子項的原因。 – Prince

+0

你可以把getchildhtml()調用到你想要的地方。 – Shrikant

+0

是的,但你的解決方案不顯示任何東西,我使用了getChildHtml的output =「toHtml」它的作品,但它顯示了頁腳下的塊,我不想要這個,我想在getChildHtml的位置顯示它。 – Prince