{{block class="Class_path" name="xyz" template="Package_Module::file.phtml" id="6"}}

{{block class="Class_path" name="xyz" template="Package_Module::file.phtml" id="7"}}

{{block class="Class_path" name="xyz" template="Package_Module::file.phtml" id="8"}}

I have used these three blocks in my CMS page but when I get the id, I am always getting 6

What I understand from this is my first block is stored or cached and its always returned

I changed the block name to different values but got the same result.

I changed the values to this and still getting the same result.

 {{block class="Class_path" name="xyz1" template="Package_Module::file.phtml" menuid="6"}}

 {{block class="Class_path" name="xyz2" template="Package_Module::file.phtml" menuid="7"}}

 {{block class="Class_path" name="xyz3" template="Package_Module::file.phtml" menuid="8"}}
  • how do you get the id?
    – Marius
    Apr 26, 2017 at 13:55
  • @amit Block names should be unique per page. Directly from Magento 2's layout dev guide "Name that can be used to address the block to which this attribute is assigned. The name must be unique per generated page. If not specified, an automatic name will be assigned in the format ANONYMOUS_n" More information at; devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/…
    – Eirik
    Apr 26, 2017 at 14:12
  • I am using $this->getMenuid() in my block
    – Amit Singh
    Apr 27, 2017 at 5:20

2 Answers 2


Sometimes in magento some blocks are cached like Magento\Theme\Block\Html\Topmenu you can use below code for remove your block from cache. Insert below code in your block file.

public function getCacheLifetime()
    return null;

I don't know why this happens, but I can give you some debug advice.
the directives {{block...}} are parsed in Magento\Email\Model\Template\Filter::blockDirective().
This method interprets the parameters in 2 ways, in this order:

  • if there is a class attribute then it instantiates the class and calls setters for the other parameters from the class it has just instantiated. But it ignores the parameters ['class', 'id', 'output'].
  • if there is no class attribute then it will search for id and load the cms block with the id you provide.

In your case, the id parameter should be ignored completely because you have the class parameter specified.
Check where do you get that id 6 from.

  • Actually I mistyped menuid with id in my question
    – Amit Singh
    Apr 27, 2017 at 5:16

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.