I have create module. i call it int cms page.

{{block class="Namespace/Module/Block/Custom" template="Namespace_Module::html/my.phtml" custom_id=1}}

how to get custom_id value? in Namespace/Module/Block/Custom or in my.phtml?

  • 2
    Try with : $block->getData('custom_id'); Commented Feb 7, 2017 at 8:49
  • it works ? let me know if it still not works Commented Feb 7, 2017 at 9:02

3 Answers 3


In your .phtml file you need to use block :

Try below code :

$custom_id = $block->getData('custom_id'); 
echo $custom_id;

You need to use


$this inside a template refers to the instance of the PHP template engine used for rendering the block, not the block itself.


In .phtml file

$custom_id = $this->getData("custom_id");

In your Block file

public function __construct(
            \Magento\Catalog\Block\Product\Context $context, 
            array $data = []
) {

    parent::__construct($context, $data);
  • i tried it and $result null.
    – xanka
    Commented Feb 7, 2017 at 8:39

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.