1

I have a custom module and on that I have a template file. I want to show that template in a particular category instead of it displaying in all the category pages.

How can I achieve that?

Anyone please suggest me to achieve this result?

  • You can use static block and call your custom template in this block after this static block select in particular category. – Payal Patel Feb 8 at 5:59
  • @PayalPatel, Could you please explain a little bit? As I have created a module and now the template file is displaying in all the categories – Siva Feb 8 at 6:02
  • Can you please tell me that template file displaying in all categories or particular categories ? – Payal Patel Feb 8 at 6:08
  • Now, Its displaying all categories but I want to show that only for a particular category. – Siva Feb 8 at 6:09
  • 1
    I was going to post the same answer as below, please check. – Payal Patel Feb 8 at 6:17
5

For that, you just need to create one static block and call you .phtml file like the below example.

{{block class="\Magento\Framework\View\Element\Template" template="Vendor_Module::product/category_customdata.phtml"}}

Then you just need to call these blocks in a specific category. Check below image for your reference.

enter image description here

That's it.

I hope it helps you.

|improve this answer|||||
  • Before I try your solution, I have to remove the template in all category page so I have removed layout from the module but still I can see the template file in category pages. How can I remove that template file in all category pages? – Siva Feb 8 at 6:41
  • It's not related to this question. But, for that, I think you need to remove it manually. – MK- Feb 10 at 6:00
1

You can try to load block with template with

catalog_category_view_id_[Cat Id].xml

Reference with similar question:

https://stackoverflow.com/questions/36451706/magento2-multiple-category-layouts?rq=1

|improve this answer|||||
1
  1. Create CMS block
{{block class="Magento\Framework\View\Element\Template" name="formblock" template="Vendor_Module::myfiles/myfile.phtml"}}
  1. In your category, set that CMS block.

enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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