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


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();?>
| improve this answer | |
  • @shail if this answer help you then you can mark as accepted, so other users take benifit if they face same problem – Murtuza Zabuawala Jul 27 '18 at 6:43
  • @ Murtuza i vote cast for "This answer is useful". – shail Jul 27 '18 at 6:50
  • @shail you can hit that green ` ✔` button next to my answer for this – Murtuza Zabuawala Jul 27 '18 at 6:56

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"}}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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