1

I have this code, which is rendering a static block in a template file (phtml).

$_html = $this->getLayout()
        ->createBlock('Magento\Cms\Block\Block')
        ->setBlockId('test-block')
        ->toHtml();

Is it possible to pass a variable into the static block?

Example.

$_html = $this->getLayout()
    ->createBlock('Magento\Cms\Block\Block')
    ->setData('test','test 123')
    ->setBlockId('test-block')
    ->toHtml();

And then in the static block display it like this {{var test}}

1 Answer 1

-1

Try this:-

$_html = $this->getLayout()->createBlock("Vender\Module\Block\test")->setData('test','test 123')->setTemplate("Vender_Module::test.phtml")->toHtml();

you can display data using this way

$this->getData('test');

1
  • I want to access this variable in the static block. I can't use PHP there.
    – puntable
    Oct 18, 2021 at 13:55

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.