0

I use Magento 2.2.4 and I want to add a static block with the name "support" in the right side of the top menu, but what I try not working.

I try to add this in the phtml file

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

I try to add this in the Magento_Theme/layout/default.xml

<referenceContainer name="page.top">
   <block class="Magento\Cms\Block\Block" name="support">
       <arguments>
            <argument name="support" xsi:type="string">support</argument>
       </arguments>
   </block>
</referenceContainer>

I do something wrong?

Thank you

11
  • The code looks fine. Have you flushed cache? Jun 22, 2018 at 12:20
  • the cache is off, but yes I try this too. I rebuild the static files too, nothing not work.
    – Robert
    Jun 22, 2018 at 12:21
  • block is enable for sure
    – Robert
    Jun 22, 2018 at 12:26
  • is not work with $this too
    – Robert
    Jun 22, 2018 at 12:29
  • Is this a new theme? You might have to check your database theme table. If your theme is set to 'virtual theme' all xml changes won't work, despite wether the code is fine or not
    – Koen
    Jun 22, 2018 at 12:41

1 Answer 1

1

Try the below code in your Magento_Theme/layout/default.xml file:

<referenceContainer name="page.top">
   <block class="Magento\Cms\Block\Block" name="support">
       <arguments>
            <argument name="block_id" xsi:type="string">support</argument>
       </arguments>
   </block>
</referenceContainer>

Instead of

<referenceContainer name="page.top">
   <block class="Magento\Cms\Block\Block" name="support">
       <arguments>
            <argument name="support" xsi:type="string">support</argument>
       </arguments>
   </block>
</referenceContainer>
2
  • Indeed like this is okay, thank you so much for your help.
    – Robert
    Jun 22, 2018 at 18:14
  • Welcome. Happy to help! Jun 22, 2018 at 18:22

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.