2016-03-08 16 views

回答

9

使用unsetElement()方法刪除塊。 像

$layout = $this->getLayout(); 
$block = $layout->getBlock('catalog.topnav'); // block name 
$layout->unsetElement('catalog.topnav'); 
+0

我試圖刪除'contactForm'這樣,但沒有成功... –

0

你可以嘗試這種方式。例如,我除去側邊欄比較,所以我default.xml中覆蓋到應用程序/設計/前端/ Your_Theme/THEME_NAME/Magento_Catalog /佈局

<?xml version="1.0"?> 
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> 
<body> 
    <referenceBlock name="catalog.compare.sidebar" remove="true"/> 
</body> 

0

從頁面移除特定塊,打開您的自定義佈局XML並把下面的代碼在body標籤

<?xml version="1.0"?> 
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> 
    <body><referenceBlock name="Your_Block" remove="true"/> 
    </body> 
    </page> 

變化Your_Block這樣一來你的塊名稱必須去除