2

How to setTemplate in custom module for search.

Spacename/Modulename/view/frontend/layout/default.xml

 <?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. 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>

    <referenceBlock name="topSearch">
    <arguments>
        <argument name="template" xsi:type="string">Spacename_Modulename::form.mini.phtml</argument>
    </arguments>
</referenceBlock>

    </body>
</page>

just want to change his template file. how to do that?

this solution not working for me.

3

Using the arguments tag

NB: this method seems to be buggy when this post is written: https://github.com/magento/magento2/issues/3356

<referenceBlock name="top.search">
    <arguments>
        <argument name="template" xsi:type="string">Vendor_Module::form.mini.phtml</argument>
    </arguments>
</referenceBlock>

Using the attribute

<referenceBlock name="top.search" template="Vendor_Module::form.mini.phtml" />

Using the action tag

NB: this tag is deprecated now.

<referenceBlock name="top.search">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">Vendor_Module::form.mini.phtml</argument>
    </action>
</referenceBlock>
| improve this answer | |
  • unfortunately not working for me. when i add this <referenceBlock name="top.search" remove="true"/> it working in default.xml but above code is not working. – Qaisar Satti Sep 9 '16 at 7:37
  • @QaisarSatti well that's the right way though. You'll have to debug your layout to find out what your problem is. Could be that the block has been removed/renamed. Or your module is not properly configured – Raphael at Digital Pianism Sep 9 '16 at 7:44
  • i update the question with my xml code. – Qaisar Satti Sep 9 '16 at 7:49
  • @QaisarSatti are you sure you have this file: app/code/Spacename/Modulename/view/frontend/templates/form.mini.phtml ? – Raphael at Digital Pianism Sep 9 '16 at 7:52
  • @QaisarSatti did you try with the <action> tag instead ? – Raphael at Digital Pianism Sep 9 '16 at 7:52

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