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?

7
  • You can use static block and call your custom template in this block after this static block select in particular category. Feb 8, 2020 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
    – MagentoDev
    Feb 8, 2020 at 6:02
  • Can you please tell me that template file displaying in all categories or particular categories ? Feb 8, 2020 at 6:08
  • Now, Its displaying all categories but I want to show that only for a particular category.
    – MagentoDev
    Feb 8, 2020 at 6:09
  • 1
    I was going to post the same answer as below, please check. Feb 8, 2020 at 6:17

3 Answers 3

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.

2
  • 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?
    – MagentoDev
    Feb 8, 2020 at 6:41
  • It's not related to this question. But, for that, I think you need to remove it manually.
    – MK Patel
    Feb 10, 2020 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

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

Your Answer

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

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