How can I get ID from this code which is typed into CMS page content?

{{block class="Vendor\Module\Block\CategoryList" category_id="49" template="Vendor_Module::subcategorylist.phtml"}}

I need to get ID into my Block file.

Which classes I have to inject and what methods I need to write into Block file?

3 Answers 3


Try this in your block file and phtml file



In Magento 2 You can get Category Id by using following code

$categoryid = $block->getData('category_id');

I hope this will help


At Block, you can get that parameter value by

        $categoryid = $this->getData('category_id');

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.