2

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.

Update:
I want to do it through code.

1

3 Answers 3

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

use this to add a static block via layout XML file

AND

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

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

2

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!

1
  • i want to add that by code :) not by admin panel
    – coding mv
    Mar 12, 2021 at 13:23
0
<?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">
    <head>
        <css src="vendor_module::css/advancelayoutmanagement.css" />
    </head>
    <body>
        <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">
            </block>
        </referenceContainer>
    </body>
</page>

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.