0

I have a phtml that contain button like this in my custom module :

app/code/Vendor/Module/view/templates/button.phtml

<button> <span> <?= __('New Button') ?> </span> </button>

i want to add this phtml in top of layered navigation filter, so it will look like this:

enter image description here

How can i do this using custom module, not from theme?

1

I have cerate the custom module and after move the button

/Mage/Mohit/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Mage_Mohit',
    __DIR__
);

/Mage/Mohit/etc/module.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © EAdesign by Eco Active S.R.L.,All rights reserved.
 * See LICENSE for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Mage_Mohit" setup_version="1.2.9"/>
</config>

/Mage/Mohit/view/frontend/layout/catalog_category_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Magento\Catalog\Block\Category\View" name="category.description.bottom" template="Mage_Mohit::product/list.phtml" />
        </referenceContainer>
        <move element="category.description.bottom" destination="page.main.title" before="category.product.list.additional"/>

    </body>
</page>

/Mage/Mohit/view/frontend/templates/product/list.php

<?php
    <button> 
        <span> 
            <?= __('New Button') ?> 
        </span> 
    </button>
?>  

And finally apply this css this class :-

.page-main>.page-title-wrapper .page-title { display: flex; }

And after cache clean and check

enter image description here

This file code is you want to display button in catalog search page check code :-

/Mage/Mohit/view/frontend/layout/catalogsearch_result_index.xml

<?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" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Magento\CatalogSearch\Block\Result" name="category.description.bottom" template="Mage_Mohit::product/list.phtml" />
        </referenceContainer>
        <move element="category.description.bottom" destination="page.main.title" before="-"/>

     </body>
</page>

And same apply css :-

.page-main>.page-title-wrapper .page-title { display: flex; }

enter image description here

Any Query let me know.

thanks.

| improve this answer | |
  • thank , ill try this and let you know – jojo Apr 7 at 6:31
  • Okay and helpful answer so accpet and upvote answer because helpful to other community... Thanks. – Mohit Patel Apr 7 at 6:37
  • i tried to access it from /catalogsearch/result/?q=wine but the button does not show up – jojo Apr 7 at 7:11
  • Hello @jojo Please check my update answer and helpful so accept and upvote answer because helpful to other community. Thanks. – Mohit Patel Apr 7 at 17:18
  • Thanks a lot , it works – jojo Apr 8 at 1:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.