7

I have static block in backend named as "varmo_custom_block_for_header".

I want to echo that block content into a header.phtml file.

I trying this way but not succeed :

 <?php echo $block->getLayout()->createBlock('magento\Cms\Block\Block')->setBlockId('varmo_custom_block_for_header')>toHtml();?>

But getting error as :

Fatal error: Call to undefined function toHtml() in /opt/lampp/htdocs/xyz/app/design/frontend/xyzthemes/mo/xyzthemes_mo/templates/html/header.phtml on line 47

2 Answers 2

13

There is a syntax error in your code in near >toHtml

It should be ->toHtml()

<?php echo $this->getLayout()->createBlock(\Magento\Cms\Block\Block::class)->setBlockId('varmo_custom_block_for_header')->toHtml();?>
3
  • @shail if this answer help you then you can mark as accepted, so other users take benifit if they face same problem Commented Jul 27, 2018 at 6:43
  • @ Murtuza i vote cast for "This answer is useful".
    – shail
    Commented Jul 27, 2018 at 6:50
  • @shail you can hit that green ` ✔` button next to my answer for this Commented Jul 27, 2018 at 6:56
2

You can try this:

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>

This is another option:

{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}

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.