1

I am using Magento 2.1 and I am trying to add one custom form in catalog page.

I override the catalog_category_view to my custom module

and use this code

 <referenceContainer name="columns.top">
        <container name="category.view.container" htmlTag="div" htmlClass="category-view" after="-">
         <block class="Vendor\Module\Block\Search\Form" name="category.pr" template="Vendor_Module::category/form.phtml">
                       </container>
    </referenceContainer>

buts it's not working. is there any other way to do this???

1
  • Check my answer, you did little mistake in catalog_category_view.xml. Jul 9, 2017 at 16:02

1 Answer 1

3

Create catalog_category_view.xml and call your custom form block

app/code/Vendor/Module/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="category.view.container">
            <block class="Magento\Framework\View\Element\Template" name="custom.category.form" template="Vendor_Module::category/form.phtml" />
        </referenceContainer>
    </body>
</page>

Now create custom form.phtml at

app/code/Vendor/Module/view/frontend/templates/category/form.phtml

<?php

echo "<h1>Test Form on category page</h1>";

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.