How to call static block in knockout template file?
You can create a module that will make your cms block message available to the KO template by adding to the checkout config.
In Your/Module/etc/frontend/di.xml
we add a new config provider to the checkout config:
<?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="cms_block_config_provider" xsi:type="object">Your\Module\Model\ConfigProvider</item>
</argument>
</arguments>
</type>
</config>
In Your/Module/Model/ConfigProvider.php
we have the code that fetches the cms block's html:
<?php
namespace Your\Module\Model;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\View\LayoutInterface;
class ConfigProvider implements ConfigProviderInterface
{
/** @var LayoutInterface */
protected $_layout;
public function __construct(LayoutInterface $layout)
{
$this->_layout = $layout;
}
public function getConfig()
{
$cmsBlockId = 1; // id of cms block to use
return [
'cms_block_message' => $this->_layout->createBlock('Magento\Cms\Block\Block')->setBlockId($cmsBlockId)->toHtml()
];
}
}
Now you should overwrite the shipping.html KO template in your theme where you can display the cms block like so:
<div data-bind="html: window.checkoutConfig.cms_block_message"></div>
Note: if you want to use html tags that contain double quotations (for example an html a tag) in the static block you should escape the double quotations with a backslash. For example:
Accept our <a target=\"_blank\" href=\"/privacy-policy\">privacy policy</a>