We are able to remove block in Magento1 with unsetBlock() method, but in Magento2 it is not working. So, please help how can remove block in Magento2 programmatically ?
Use unsetElement() method to remove block.
as like
$layout = $this->getLayout();
$block = $layout->getBlock('catalog.topnav'); // block name
$layout->unsetElement('catalog.topnav');
You need to try this way, for example, I am removing compare from the sidebar so I override default.xml to app/design/frontend/Your_Theme/theme_name/Magento_Catalog/layout
<?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>
To Remove particular block from page, Open your custom layout xml and place the below code under body Tag
<?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>
Change Your_Block this one to your block name need to be remove
Ideally there are different ways to do this. The best way of doing it is using a layout file.
1) If you have build a module you can create a layout which is an xml file in app/code/Namespace/Your_Module/view/frontend/layout/frontname_controllername_controlleraction.xml and add the below code
<?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">
<referenceBlock name="block_name" remove="true" />
</page>
2) If you have not created a custom module of your's you can simply write a custom xml in app/design/frontend/Custom_Theme/Theme_name/Module_Name/layout and add the below code.
<?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">
<referenceBlock name="block_name" remove="true" />
</page>
Related
How we can add column to Sales order history content into customer account.
What are methods for add a column to sales_order_history page without editing view/frontend/templates/order/history.phtml?
You don't need to touch view/frontend/templates/order/history.phtml template file to add aditional column into customer sales order history page.
copy layout view/frontend/layout/sales_order_history.xml to your theme and add addtional column header to sales.order.history.extra.column.header block and render column data using sales.order.history.extra.container block.
You have all set now.
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<!-- This will add additional column header to order list -->
<referenceBlock name="sales.order.history.extra.column.header">
<block class="Magento\Framework\View\Element\Template" name="your.additional.column.header" template="Namespace_Module::columnheader.phtml"/>
</referenceBlock>
<!-- You can access current order using $this->getOrder() inside the template ">
<referenceBlock name="sales.order.history.extra.container">
<block class="Magento\Framework\View\Element\Template" name="your.additional.column.data" template="Namespace_Module::columndata.phtml"/>
</referenceBlock>
</body>
</page>
I have an easier and shorter solution(date column in the example):
1- Create in your theme/extension into layout folder-> sales_order_history.xml and copy:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="sales.order.history.extra.container" template="Magento_Sales::order/date/data.phtml"/>
</body>
</page>
2- Create the template for the data in templates/date/data.phtml and copy:
<?php
/* #var $block \Magento\Sales\Block\Order\History\Container */
?>
<td data-th="<?= $block->escapeHtml(__('Date')) ?>" class="col date">
<?= $block->escapeHtml($block->getOrder()->getCreatedAt()) ?></td>
How to move topmenu inside header wrapper reference
[magentoroot]vendor/magento/module-theme/view/frontend/layout/default.xml
I want to move catalog.topnav inside header-wrapper
<referenceContainer name="page.top">
<block class="Magento\Theme\Block\Html\Topmenu" name="catalog.topnav" template="html/topmenu.phtml" ttl="3600"/>
</referenceContainer>
<referenceContainer name="header-wrapper">
</referenceContainer>
Thanks
Add Following code in [magentoroot]vendor/magento/module-theme/view/frontend/layout/default.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="catalog.topnav" destination="header-wrapper" after="logo"/>
</body>
</page>
To get this to work, I had to move the whole navigation.sections block. Otherwise the menu would look broken with mobile resolutions. I'm working with Magento 2.1.1 and my theme inherits from blank.
In /app/design/frontend/<Vendor>/<theme>/Magento_Theme/layout/default.xml add this:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="navigation.sections" destination="header-wrapper" after="logo"/>
</body>
</page>
I suggest you create a structure in your
app/design/frontend/yourVendor/yourTheme/Magento_Theme/page_layout
Inside create your default.xml and paste this:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="catalog.topnav" destination="header-wrapper" after="logo"/>
</body>
</page>
I tried to replace the default discount block. Unfortunately, the block is always located on the bottom of the container. I can't move it to the default block position.
my xml -
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<remove name="checkout.cart.coupon"/>
<referenceContainer name="cart.discount">
<block class="{namespace}\Coupons\Block\Coupon" name="checkout.cart.coupon2" as="sadasdasd" template="test.phtml"/>
</referenceContainer>
<move element="cart.discount" destination="checkout.cart.container" before="checkout.cart.order.actions.gift_options" />
</body>
</page>
screen of result -
I think checkout.cart.order.actions.gift_options is not an immediate child of checkout.cart.container, so the 'before' clause is not finding position you want and is defaulting to 'last child' as a default behavior.
My code :
<reference name="before_body_end">
<block type="test/test" template="test/test.phtml" name="test-test" />
</reference>
when i change to
<reference name="after_body_end">
<block type="test/test" template="test/test.phtml" name="test-test" />
</reference>
then it is not working. please help
It doesn't work because you are referencing ...well...nothing. The block with name after_body_end does not exist.
I will explain how to add it but first I want to make it clear that I don't approve of adding html outside the body tag. This may cause issues on some browsers.
First you need to create the block with name after_body_end.
For this edit the file app/design/frontend/{interface}/{theme}/layout/page.xml and look for this :
<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
<label>Page Bottom</label>
</block>
Right under that add the following.
<block type="core/text_list" name="after_body_end" as="after_body_end" translate="label">
<label>Page Unde the body tag</label>
</block>
Now your block exists. You just have to add it to your page. For this edit the following files all located in app/design/frontend/{interface}/{theme}/template/page/:
1column.phtml
2columns-left.phtml
2columns-right.phtml
3columns.phtml
empty.phtml
popup.phtml
print.phtml
For all these files add under the </body> line this:
<?php echo $this->getChildHtml('after_body_end') ?>
Clear the cache and enjoy.
I am using the Sandcastle Help File Builder and would like to include colorized HTML code snippets in the "Conceptual Content". Is this possible and if so, how?
I have tried <code>, <codeExample>, and <sampleCode language="HTML" />.
The best result so far is to HTML-encode the sample HTML and place it in a .snippets file like so.
<?xml version="1.0" encoding="utf-8" ?>
<examples>
<item id="htmlSnippet">
<sampleCode language="HTML">
<span>My Html</span>
</sampleCode>
</item>
</examples>
Then reference it in the .aml file.
<codeReference>htmlSnippet</codeReference>
I would prefer to have it colorized, but I can't figure out a way to add the formatting.
According to the MAML Guide, the proper way of doing this is to use a <code> tag with a CDATA section:
<code language="xml" title="Example Configuration">
<![CDATA[
<span>My Html</span>]]>
</code>
The contents of the CDATA section will be treated as a literal string, and indentation will be preserved.
I know this is old, but Sandcastle supports html as xml. I figured I should comment in case anyone else comes across this post as I did.
This should work:
<?xml version="1.0" encoding="utf-8" ?>
<examples>
<item id="htmlSnippet">
<sampleCode language="xml"><!CDATA[[
<span>My Html</span>
]]>
</sampleCode>
</item>
</examples>
If you're using Sandcastle Help File Builder, you may create your own syntax parser as described here and here, although xml is available by default... using the XAML filter's generator, which is defined here if you want to look at the config:
<generator type="Microsoft.Ddue.Tools.XamlUsageSyntaxGenerator"
assembly="{#SandcastlePath}ProductionTools\SyntaxComponents.dll">
<filter files="{#SandcastlePath}Presentation\Shared\configuration\xamlSyntax.config" />
</generator>
According to the SHFB documentation for the Code Block Component, you should be able to just use the <code>.
I got it to work without a problem; here's what I did:
test.html
<html>
<head>Something!</head>
<body>
<h1>Heading</h1>
<!-- #region myhtml -->
<p>Paragraph</p>
<div>Div for <strong>Good</strong> <em>measure</em>.</div>
<!-- #endregion -->
</body>
</html>
SomethingorOther.aml
<code language="html" source="../Examples/test.html" region="myhtml" />
Result:
Please note that in the preview, your sample will appear as unhighlighted XML, but when you build the documentation, everything should like just fine.