
Watch for this line Vendor_ModuleName/cms-block and change it. As you can see, I have set 1 for sortOrder with means my component will be loaded first inside address form. As I mentioned above, components load order is managed inside XML files. That component will hold the content of our CMS block. We have now added new UIcomponent to the address form. With this content: uiComponent Vendor_ModuleName/cms-block 1 Then, create app/code/Vendor/ModuleName/view/frontend/layout/checkout_index_index.xml Next, we will create new entry for Config Provider by creating or editing Vendor/ModuleName/Model/ConfigProvider.php: _layout = $layout $this -> cmsBlock = $this -> constructBlock ( $blockId ) } public function constructBlock ( $blockId ) In above example, path is Vendor\ModuleName\Model\ConfigProvider. Please make sure that and paths match the name of your block.

In the above example, a block is named “checkout_cms_block” (it works with id or identifier of the block). With this code, we are adding new entry to ConfigProvider and we are also declaring CMS block which will be used to parse data from.

Adding CMS block in Checkout sidebarĮdit Vendor/ModuleName/etc/frontend/di.xml file:

Please, don’t forget to do setup:upgrade after you have created your module. I will use Vendor for vendor and ModuleName for module name.Īfter you have created module with all necessary files, we will add/edit few of them to achieve our goals. For example, you can create a module with all necessary files with just one command. I would suggest that you use netz98 magerun CLI tools extension which is a helpful asset during development.
Blockblock cms how to#
If you don’t know how to create Magento 2 module, follow steps in this article by my colleague Hrvoje Ivancic. If you want to hang out with components, act as a component! Creating a module That way, our CMS content becomes part of the checkout flow and it is loaded alongside with other components. Idea is to take content from CMS block and put it in JS object which will then be outputted to frontend via Knockout Bindings. However, each approach has the same initial step. Since the whole checkout is bundled from various JS components, approaches on this task will vary depending on the CMS block position. Hopefully, there is a way to insert CMS block inside checkout flow. In short, the whole checkout is dynamically loaded and we can’t put anything “static” inside. To pull the data from the server, Magento uses global Javascript variable window.checkoutConfig which is then used by Knockout.js to compute and display information on the frontend. Magento 2 defines these components and their mutual relationship in a large XML file.
Blockblock cms series#
CMS block is now part of the content and will be rendered/delivered when needed.Īdding CMS block to Magento 2 Checkout is a bit more complex task since the whole checkout is built up from a series of KnockoutJS components which are then rendered using the knockout.js templating system. We then need to call it in templates and that’s it. I personally like to use CMS blocks whenever I can so that content of the store becomes more “modular” and easily manageable.ĬMS blocks at checkout can have many usages like displaying some information for specific shipping method of some promotional content in order to convince the user to spend more before he checks out.Īdding CMS block to some specific position/page is not such a hassle, we just need to “register” our CMS block in layouts and define order/position of our CMS block.
Blockblock cms code#
CMS blocks can carry plain text or chunks of HTML/JS/CSS code which means they can be used for even more complex content delivery like sliders, product carousels etc. CMS blocks can be used to display promotional banners, sale blocks, return policies, important information message on some sections of the store etc. Using CMS blocks, site administrator can easily manipulate content of the store.

Working with CMS blocks was one of the reasons Magento was and is so popular.
