I need to override admin login page in magento2 - magento

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>

Related

Magento 2.4.5 cannot remove container

I cannot remove container "header.panel.wrapper" specifically in my custom theme in magento 2.4.5.
If I add the line <referenceBlock name="header.panel.wrapper" remove="true"/> in the file from luma theme: vendor/magento/theme-frontend-luma/Magento_Theme/layout/default.xml, it removes. But if I create this file in my custome theme: app/design/frontend/Singree/walkbeyond/Magento_Theme/layout/default.xml, with the same content as the luma-theme file, it just won't remove.
This is the code of file Magento_Theme/layout/default.xml from my custom theme:
<?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.panel">
<referenceBlock name="header.panel.wrapper" remove="true"/>
<block class="Magento\Framework\View\Element\Html\Links" name="header.links">
<arguments>
<argument name="css_class" xsi:type="string">header links</argument>
</arguments>
</block>
</referenceContainer>
<referenceContainer name="footer">
<block class="Magento\Store\Block\Switcher" name="store_switcher" as="store_switcher" after="footer_links" template="Magento_Store::switch/stores.phtml"/>
</referenceContainer>
<referenceBlock name="report.bugs" remove="true"/>
<move element="copyright" destination="before.body.end"/>
</body>
</page>
if you search for header.panel.wrapper you see its not a block, but it is defined as a container. So try and use:
<referenceContainer name="header.panel.wrapper" remove="true"/>
That should work in your custom theme.

Changing from magento plugin does not make effect , but changing from magento\vendor shows effect

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

Magento2 theme layout files suddenly stopped working

I am brand new to Magento, and am using Magento 2. I have a custom theme that has been working just fine. Suddenly, the files in my custom theme's Magento_Theme/layout folder seem to not be loading. In my layout folder I have default_head_blocks.xml and default.xml. BOTH files suddenly stopped working.
Here is my default_head_blocks.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">
<head>
<css src="css/bootstrap.min.css" />​
<css src="css/styles-m.css" />
<css src="css/styles-l.css" media="screen and (min-width: 768px)"/>
<script src="js/bootstrap.min.js"/>
<script src="js/site.js"></script>
</head>
</page>
And my 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.panel">
<block class="Magento\Framework\View\Element\Html\Links" name="header.links">
<arguments>
<argument name="css_class" xsi:type="string">header links</argument>
</arguments>
</block>
</referenceContainer>
<referenceContainer name="footer">
<block class="Magento\Theme\Block\Html\Footer" name="absolute_footer" template="html/absolute_footer.phtml" />
</referenceContainer>
<referenceBlock name="report.bugs" remove="true"/>
<referenceBlock name="store.settings.currency" remove="true"/>
<referenceBlock name="catalog.compare.sidebar" remove="true"/>
<referenceBlock name="advanced-search-link" remove="true"/>
<referenceBlock name="skip_to_content" remove="true"/>
<referenceBlock name="store_switcher" remove="true"/>
<referenceBlock name="navigation.sections" remove="true"/>
<referenceBlock name="top.search" remove="true"/>
<referenceBlock name="footer_links" remove="true"/>
<move element="copyright" destination="before.body.end"/>
<move element="logo" destination="navigation.sections"/>
<move element="form.subscribe" destination="footer"/>
<move element="catalog.topnav" destination="header.container"/>
<move element="top.links" destination="footer"/>
</body>
</page>
As I stated the files were working perfectly fine at one point.
The files in my Magento_Theme/templates/html folder load just fine. Seems to only be the files in my layout folder.
Any ideas why this would be happening or how to fix it?
From my experience, instances like this would require you to do the following.
Clean Cache:
php bin/magento cache:clean
Flush Cache:
php bin/magento cache:flush
(optional) if clearing cache doesn't seem to show any changes, you might need to do a static deploy.
Static Deploy: Note: this will take a bit of time depending on your system.
php ./bin/magento setup:static-content:deploy --theme <your theme example myTheme/Default>
After these processes you can try and reload the page again.
You have added <script> in a wrong way inside inside the file default_head_blocks.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">
<head>
<css src="css/bootstrap.min.css" />​
<css src="css/styles-m.css" />
<css src="css/styles-l.css" media="screen and (min-width: 768px)"/>
<script src="js/bootstrap.min.js"/>
<script src="js/site.js"/>
</head>
</page>
Static Deploy:
php bin/magento setup:static-content:deploy
Flush Cache:
php bin/magento cache:flush
Just go to website database, open theme table and chagne type = 0 for your current theme. That's it :)
There's an issue with default_head_blocks.xml if the theme type is set to virtual. Check the type field in the theme table. If it's set to 1, try setting it to 0. Then clear the cache and reload the page. See if that does the trick.
See also: https://github.com/magento/magento2/issues/4330

Overwriting Templates with custom Module in Magento 2

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.

Magento 2 - How to change htmlClass, htmlId attributes by referenceContainer or another way?

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

Resources