Magento 2: How to add custom form on category page?
-
10-10-2020 - |
سؤال
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???
المحلول
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>";
لا تنتمي إلى magento.stackexchange