0

I want change layout of catalaog_category_view.xml but i can't. I override block category.products and it's work but how can i add my own block to existing category.products block? Because i want add my own element above of category.products element. I was trying add block and move element, add to referenceContainer content and move before category.products and nothing happened. Still the same page exists. Can you help me how can i add block inside category.products or above category.products.

            <block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml">
            <block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">
                <container name="category.product.list.additional" as="additional" />
                <block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
                    <block class="Magento\Framework\View\Element\Template" name="category.product.type.details.renderers.default" as="default"/>
                </block>
                <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="category.product.addto" as="addto">
                    <block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
                           name="category.product.addto.compare" as="compare"
                           template="Magento_Catalog::product/list/addto/compare.phtml"/>
                </block>
                <block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
                    <block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
                </block>
                <action method="setToolbarBlockName">
                    <argument name="name" xsi:type="string">product_list_toolbar</argument>
                </action>
            </block>
        </block>

This is block category.products from Magento_Catalog. I want add my block above this one:

 <block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml">

Or:

            <block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml"><!-- Before category.products.list -->
            <block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">

Anyone can help me? I will be really grateful!

13
  • Have you tried with this? <move element="yourblock" destination="content" before="category.products" /> Commented May 30, 2019 at 12:41
  • <referenceBlock name="category.products"> <action method="setTemplate"> <argument name="template" xsi:type="string">MGS_Landing::category/products.phtml</argument> </action> </referenceBlock> - This code override standard category.products. I'm beginner developer of magento2. Where i must create additional block which will show above category.products? Inside referenceBlock or somewhere else?
    – Pepe44
    Commented May 30, 2019 at 12:53
  • Do you want to replace default magento's layout of category.products block or want to create a new block before category.products block? Commented May 30, 2019 at 13:00
  • I solved this problem with your tips :) <block class="ModuleOwn\Landing\Block\Landing" name="landingown" template="ModuleOwn::category/landing/grid.phtml"/> <referenceBlock name="category.products"> <action method="setTemplate"> <argument name="template" xsi:type="string">ModuleOwn::category/products1.phtml</argument> </action> </referenceBlock> <move element="landingown" destination="content" before="category.products" />
    – Pepe44
    Commented May 30, 2019 at 13:05
  • Great :) I'm posting my answer, may be it may helpful to anyone else. Commented May 30, 2019 at 13:07

1 Answer 1

0

You need to use <move> element in following way:

<move element="yourblock" destination="content" before="category.products" />

Hope may helpful to anyone.

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.