5

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?

8

Try this in your block file and phtml file

$this->getData("category_id");

5

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

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

I hope this will help

4

At Block, you can get that parameter value by

    if($this->hasData('category_id'))
    {
        $categoryid = $this->getData('category_id');
    }

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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