I have added a static CMS bock by set up patch, so I will now put it in a specific area like in cart information pop up or a different layout like payment checkout before payments methods.

I want to do it through code.


3 Answers 3

<referenceContainer name="content">
  <block class="Magento\Cms\Block\Block" name="unick_block_name">
      <argument name="block_id" xsi:type="string">your_block_identifier</argument>

use this to add a static block via layout XML file


echo $this->getLayout()

use this to add a static block via .phtml file

And If you want it to display it on the HTML template page then store it in variable and pass it via x-init config option part then display it html bind use in KO

HTML template part I have never done but this is the possible way I believe that work


without any code intervention, what you could try is to create a new widget with CMS block type (https://docs.magento.com/user-guide/cms/widget-create.html) and set it to be displayed on 'specified page' - choose your page and see if in the 'container' dropdown you find any default option that suits your needs.

good luck!

  • i want to add that by code :) not by admin panel
    – coding mv
    Commented Mar 12, 2021 at 13:23
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <css src="vendor_module::css/advancelayoutmanagement.css" />
        <referenceContainer name="page.wrapper">
            <block class="vendor\module\Block\Widget\EditButton" before="header.container" name="add-new-header-link" template="vendor_module::widget/edit_button.phtml">

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.