0

How to write the corresponding layout xml file in Magento 2?

<?xml version="1.0"?>
<layout version="0.1.0">
 <catalogsearch_result_index>        
    <reference name="catalogsearch.leftnav">
        <action method="setTemplate">
            <setTemplate>tagalys_search/filter.phtml</setTemplate>
        </action>
    </reference>
      <reference name="content">
        <reference type="catalogsearch/result" name="search.result">
            <reference name="search_result_list">
                <reference name="product_list_toolbar">
                    <action method="setTemplate">
                        <template>tagalys_toolbar/toolbar.phtml</template>
                    </action>
                 </reference>
            </reference>
        </reference>
    </reference>
</catalogsearch_result_index>

1 Answer 1

0

In Magento 2 every layout handle is its own file.
So you don't have one big file for a module, you have many smaller files.

In you case the file should be [Namespace]/[Module]/view/frontend/layout/catalogsearch_result_index.xml with the content:

<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="catalogsearch.leftnav">
        <action method="setTemplate">
            <setTemplate>tagalys_search/filter.phtml</setTemplate>
        </action>
    </referenceBlock>
      <referenceContainer name="content">
        <!-- Not sure of the rest of the code because it's looks strange. Too many references -->
    </referenceContainer>
</page>

Basically reference becomes referenceBLock or referenceContainer depending on what you are referencing.
Containers in M2 are core/text_list blocks in M1 (content, left, right,...)

4
  • Thanks buddy, and for the referenceContainer, <reference type="catalogsearch/result" > is used in /skin/js/myjs.js as: search: { link: function(q, qf) {return '/catalogsearch/result/index/?' and <referenceName="search_rsult_list" is used in controllers/CatalogSearch/ResultController.php as $productlist = $this->getLayout()->getBlock('search_result_list')->toHtml();
    – Sushivam
    Commented Jun 18, 2016 at 11:48
  • How to give referenceType and referenceName within referenceContainer?
    – Sushivam
    Commented Jun 18, 2016 at 11:56
  • I am not even aure whar referenceType does
    – Marius
    Commented Jun 18, 2016 at 12:47
  • and <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml"> ? Should i replace with referenceBlock as above ?
    – Sushivam
    Commented Jun 18, 2016 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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