1

I want to Show Static CMS block in Magento 2 html file.

  • Let me know if still not working. – Rohan Hapani Jul 31 at 6:55
  • No it still doesn't work @RohanHapani – Prits Jul 31 at 7:31
0

Replace your di.xml with below code :

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

<type name="Magento\Checkout\Model\CompositeConfigProvider">
    <arguments>
        <argument name="configProviders" xsi:type="array">
            <item name="reg_custom_checkout_block" xsi:type="object">Reg\Checkout\Model\ConfigProvider</item>
        </argument>
    </arguments>
</type>
</config>

Update your getConfig() function from this below code :

<?php
namespace Reg\Checkout\Model;

use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\View\LayoutInterface;

class ConfigProvider implements ConfigProviderInterface
{
/** @var LayoutInterface  */
protected $_layout;
protected $cmsBlock;

public function __construct(LayoutInterface $layout, $blockId)
{
    $this->_layout = $layout;
    $this->cmsBlock = $this->constructBlock($blockId);
}

public function constructBlock($blockId){
    $block = $this->_layout->createBlock('Magento\Cms\Block\Block')
             ->setBlockId($blockId)->toHtml();
    return $block;
}

public function getConfig()
{
    $config = [];
    $config['myCustomData'] = $this->constructBlock('your-block-id');

    return $config;
}
}

inside knockout js

var customData = window.checkoutConfig.myCustomData;
console.log(customData);
| improve this answer | |
  • I have updated both files di.xml and Model file but doesn't get success. Where to put knockout.js part as such not created ant file @Rohan – Prits Jul 31 at 7:32
  • as you mention js file in question. you can use this inside js file. – Rohan Hapani Jul 31 at 7:38
  • will i add this in cms-block.js file or any other file will you please help because it show my block in my step three or anything i am not getting .@Rohan – Prits Jul 31 at 7:41
  • Yes. You can add in cms-block.js – Rohan Hapani Jul 31 at 7:42
  • I have added that under initialize function in cms-block.js. but it shows undefined customData in console.@Rohan – Prits Jul 31 at 7:51

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.