How to move topmenu inside header wrapper in magento2? - magento2

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>

Related

Magento 2.x: add column to sales order history page (FO)

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>

Can't extend/override parent "move" element

In catalog_product_view.xml in the parent theme there is this, just copied up to one line past the line Im trying to change:
<?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>
<referenceContainer name="content">
<block class="Infortis\Base\Block\Product\View" name="product-view-wrapper" template="product/view.phtml" before="-">
<container name="container_product_image_1" label="Product View, Image Column" />
<container name="container_product_primary_1" label="Product View, Primary Column, Container 1" />
<container name="container_product_primary_2" label="Product View, Primary Column, Container 2" />
<container name="container_product_secondary_1" label="Product View, Secondary Column, Container 1" />
<container name="container_product_secondary_2" label="Product View, Secondary Column, Container 2" />
<container name="container_product_lower_primary_1" label="Product View, Lower Primary Column, Container 1" />
<container name="container_product_lower_primary_2" label="Product View, Lower Primary Column, Container 2" />
<container name="container_product_lower_secondary_1" label="Product View, Lower Secondary Column, Container 1" />
<container name="container_product_lower_secondary_2" label="Product View, Lower Secondary Column, Container 2" />
<block class="Magento\Cms\Block\Block" name="block_product_secondary_bottom">
<arguments>
<argument name="block_id" xsi:type="string">block_product_secondary_bottom</argument>
</arguments>
</block>
</block>
</referenceContainer>
<move element="product.info.main" destination="product-view-wrapper" />
<move element="product.info.media" destination="product-view-wrapper" />
<move element="bundle.options.container" destination="product-view-wrapper" />
<move element="product.info.details" destination="product-view-wrapper" />
<move element="catalog.product.related" destination="product-view-wrapper" />
<move element="product.info.upsell" destination="product-view-wrapper" />
<move element="product.info.overview" destination="product.info.main" before="product.social.links" />
<move element="container_product_primary_1" destination="product.info.main" before="product.info.price" />
But I need to move it somewhere else in my child theme, like so:
<?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>
<move element="product.info.overview" destination="product.info.main" before="product.social.links" />
</body>
</page>
but it doesn't want to extend the parent and as soon as I delete the line from the parent layout file it moves it right where I need it to go. What am I doing wrong?
Edit:
It is in the Infortis > Ultimo theme
The parent xml file:
/app/design/frontend/Infortis/base/Magento_Catalog/layout/catalog_product_view.xml
The child xml file
/app/design/frontend/Infortis/childtemp/Magento_Catalog/layout/catalog_product_view.xml
Are you sure you located the correct path for the layout extend in your custom theme? Seems to me that the fallback is the issue.
Ok I finally figured out the problem. In the theme table in the database the theme was set to "1" instead of "0" like all the rest of the themes.. Im not sure how it got set to 1, but I believe that means Virtual instead of Physical.. which Im not even sure what that means either, but that solved the problem. Now my child xml extends the parent xml just fine. Thank you for your help!

Insert table in XML-view

I created a table in my controller-function onRoutePatternMatched.
Now I want to bring this table to the view.
This should be done with oTable.placeAt("sample1");
What is the right code to insert it on a specific place in my xml-view?
Home.view.xml
<?xml version="1.0" encoding="UTF-8" ?>
<mvc:View controllerName="ztest.controller.VarConf" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
xmlns:html="http://www.w3.org/1999/xhtml">
<Page>
<content id="sample1"></content>
<content id="sample2">
<Label text="{varConfDet>/chassisnr}" />
</content>
</Page>
</mvc:View>
Error:
sap-ui-core.js:152 Uncaught Error: DOM element with ID 'sample1' not found in page, but application tries to insert content.
put an id on on the page and not on its content aggregation(s): <Page id="myPge">
in Controller call this.getView().byId("myPage").addContent(oTable);
Because content os the default aggregation of the sap.m.Page you could also only call this.getView().byId("myPage").add(oTable);. Also be aware that you might to remove previously added content... Of course, you could also use different panels etc. with different ids and place the table somewhere in there...

Remove Block Programmatically in Magento2

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>

Magento how to display block outside of body tag

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.