I am trying to overwrite a template defined in /vendor/magento/module-grouped-product/view/frontend/layout/catalog_product_view_type_grouped.xml in a custom module. The file has a block named product.info.grouped defined like so:
<block class="Magento\GroupedProduct\Block\Product\View\Type\Grouped" name="product.info.grouped" before="product.info.addtocart" template="product/view/type/grouped.phtml"/>
So I created a file /app/code/FortyThree/GroupedConfigurableProduct/view/frontend/layout/catalog_product_view_type_grouped.xml and in it
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<referenceBlock name="product.info.grouped">
<action method="setTemplate">
<argument name="template" xsi:type="string">FortyThree_GroupedConfigurableProduct::product/view/type/grouped.phtml</argument>
</action>
</referenceBlock>
</layout>
and created the corresponding .phtml file but it doesn't overwrite the original template file. Is there something else I need to do to get the overwrite to register? I've tried setup:upgrade and flushing the cached nothing seems to work. I also have the Magento_GroupedProduct set in the sequence section of my module.xml to make sure its loading after.
It really doesn't seem like my catalog_product_view_type_grouped.xml is being read at all since nothing I do in there seems to do matter.
You layout file isn't good.
This should do the trick :
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info.grouped">
<action method="setTemplate">
<argument name="template" xsi:type="string">FortyThree_GroupedConfigurableProduct::product/view/type/grouped.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
Also don't forget to add a dependency to GroupedProduct in your module.
There are a few ways to check if you are referencing properly a block. You could simply use a remove, to see if that works to confirm that you have the proper block.
Related
I am pretty new to Magento and using Magento 2.2.6 to develop a plugin. I need to edit the search bar. So I added a file to my plugin folder
Plugin \view \frontend \ templates \ form.mini.phtml
This does not making any changes in my website. But when I put that same file into Magento \vendor \magento \module-search \view \frontend \templates\ form.mini.phtml . Now I want not to any files from that vendor folder. What can I do now ? Thank you.
Block form.mini.phtml define in Vendor\magento\module-search\view\frontend\layout\default.xml
<!--Vendor\magento\module-search\view\frontend\layout\default.xml -->
<referenceContainer name="header-wrapper">
<block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="Magento_Search::form.mini.phtml" />
</referenceContainer>
Overwrite using layout in your module app\code\VendorName\view\frontend\layout\default.xml
edit file form.mini.phtml and put it to app\code\VendorName\view\frontend\templates\form.mini.phtml
<!-- app\code\VendorName\view\frontend\layout\default.xml -->
<?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="header-wrapper">
<block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="VendorName_ModuleName::form.mini.phtml" />
</referenceContainer>
</body>
</page>
You can also overwrite the file in the theme without the layout file
edit file form.mini.phtml and put it to app\design\frontend\Vendor\ThemeName\Magento_Search\templates\form.mini.phtml
I need to access the magento2 admin login page using my custom module.How can i override login.phtml into my custom template file like custom-login.phtml file.
Kindly check the below coding and give me some solutions,
Check the layout file view/adminhtml/layout/adminhtml_auth_login.xml
<?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="admin.login">
<arguments>
<argument name="template" xsi:type="string">Namespace_Modulename::admin/login.phtml</argument>
</arguments>
</referenceBlock>
In my custom module added that xml file and placed the login.phtml in my custom module. The file path was view/adminhtml/templates/admin/login.phtml.
Thanks in Advance
Try following layout update to set template.
<?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="admin.login">
<action method="setTemplate">
<argument name="template" xsi:type="string">Namespace_Modulename::admin/login.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
In magento 2 Frontend developer guide, I have read that :
Certain attributes, like htmlClass, htmlId, label attributes can be
changed in extending layouts
I want to change htmlClass of the container defined in 1column.xml. Could you tell me how to do it by referenceContainer or another way ?
I used : (both html_class & htmlClass)
<arguments>
<argument name="html_class" xsi:type="string">sm-page-header</argument>
</arguments>
but not affected
Thanks!
If a container is declared in xml with the following code:
<container name="my.container" htmlTag="div" htmlClass="old-class">
<...>
</container>
You can simply override the css-class by placing the following code somewhere in your extending layout files:
<referenceContainer name="my.container" htmlClass="new-class" />
EDITED: Bellow does NOT work;
<referenceContainer name="my.name">
<arguments>
<argument name="html_tag" xsi:type="string"><![CDATA[]]</argument>
<argument name="html_class" xsi:type="string"><![CDATA[]]</argument>
<argument name="html_id" xsi:type="string"><![CDATA[]]</argument>
</arguments>
</referenceContainer>
For changing or adding new class/id you can use htmlClass and htmlId attributes in container (child of referenceContainer) instead using of referenceContainer.
Example:
1column.xml file path for custom theme
app/design/frontend/{Package}/{theme}/Magento_Theme/page_layout/1column.xml
<container name="footer-container" as="footer" before="before.body.end" htmlClass="page-footer another-class" htmlId="test-id" label="Page Footer Container" htmlTag="footer" />
for details please take a look in this built-in 1column.xml file.
vendor/magento/module-theme/view/frontend/page_layout/1column.xml
Hy,
I'm writing a custom module and I 'would like to add custom block to the app/design/frontend/mytemplate/default/template/catalog/product/view/type/default.phtml
I'cannot use the extra data place holder so I've to modify the default.phtm where I've added this code:
<?php echo $this->getChildHtml('msgdisp') ?>
in my module layout.xml I've written the following section:
<?xml version="1.0"?> <layout version="1.0.0">
<catalog_product_view>
<reference name="??????">
<block type="core/template" name="msgdisp" as="msgdisp" template="msgdisp/messaggiodisp.phtml"/>
</reference>
</catalog_product_view>
I'don't figure out what I've to put instead of ??????, so far I've tried:
product_type_data
product.info.simple
but no one of the above as worked.
In the messaggiodisp.phtml I've written a simple "placeholder" code
<!-- Hello World -->
please let me know what I'm doing wrong..
Ok, I've found a solution, I was wrong in the xml file:
<PRODUCT_TYPE_simple>
<reference name="product.info.simple">
<block type="core/template" name="msgdisp" as="msgdisp" template="msgdisp/messaggiodisp.phtml"/>
</reference>
I'm currently developing a custom module for admin and I would like to add a custom javascript before default ones.
I tried to use :
<action method="addItem"><type>skin_css</type><name>path/to/javascript.js</name><params/><if/></action>
But this line add javascript after default like prototype.js, window.js...
Is there a way to add mine before ?
Thanks !
If you want to re-order of the JavaScript files loaded in the admin, then in your layout xml handle, you will need to remove all of the script files, then add yours and then re-add them again. Please note that your js file should be in the js folder, not the skin one.
<!-- Remove the added ones -->
<action method="removeItem"><type>js</type><name>prototype/window.js</name></action>
<action method="removeItem"><type>js</type><name>scriptaculous/builder.js</name></action>
...
<!-- Add yours -->
<action method="addJs"><script>path/to/javascript.js</script></action>
<!-- Add the removed ones after -->
<action method="addJs"><script>prototype/window.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
...
go to app\design\frontend\rwd\default\layout page.xml (if you are using default theme otherwise go to yourtheme\default\layout) and you js here
<block type="page/html_head" name="head" as="head">
<action method="addJs">
<script>yourjs/yourjs.js</script>
</action>
<action method="addJs">
<script>prototype/prototype.js</script>
</action>