1

I want to add static block over the Place order button! So I have used Firecheckout extension and I found place order button here view/frontend/web/template/place-order.html on my extension.

So how can add a static block in this file?

If another way to add static block then also let me know.

1
  • conceptually you should be placing the static block in it's own block using the xml layout files. Is there a reason you need to place this in the .html template? As in, you need the block to sit between other elements in the .html file?
    – circlesix
    Commented Apr 21, 2017 at 17:54

2 Answers 2

9

To add static block over the Place order button!, you need to declare a PHTML file in checkout index anywhere in theme. STEP 1: Create a new XML file in theme

checkout_index_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template" name="static_block" template="Magento_Theme::block/summary.phtml" cacheable="false" />
    </referenceContainer>
</body>

STEP 2 : create a PHTML file in below location

app/design/frontend/{theme_package}/{theme_name}/Magento_Theme/templates/block/summary.phtml

<?php
    $summaryBlockDetail = $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('new-block')->toHtml() ?>

<script type="text/javascript">
window.summaryBlockDetail = "<?= json_encode($summaryBlockDetail)?>";
</script>

STEP 3 : Add below code in .html file else any where in .html in checkout

view/frontend/web/template/place-order.html

<div class="component-wrapper">
<div class="control">
    <span data-bind="html: summaryBlockDetail"></span>
</div>
7
  • 1
    Yes, it's perfect man, but i got static block value with html tag like<p>....</p> , i want only value without tag.
    – Dhrumin
    Commented Apr 24, 2017 at 5:10
  • Yes, I get the solution, check updated answer.
    – Dhrumin
    Commented Apr 24, 2017 at 5:18
  • One More Question, when i add multiple html like <p>...</p><b></b> etc. so it's not show on frontside. Why?
    – Dhrumin
    Commented Apr 24, 2017 at 5:50
  • A few things with step 2. The $summaryBlockDetail line needs to have <?php ?> wrapped around it. You also need to put the block HTML in the addslashes() native php function so it doesn't output quotes and break the javascript variable definition.
    – Adad64
    Commented Aug 25, 2017 at 17:52
  • Yes, You can validate your content in summary.phtml file itself in the php tag <?php ...?> Commented Sep 15, 2017 at 11:50
0

html alone can't use php commands, altough, in a mobile project we used jQuery to move static blocks from one part of the page to another onLoad. You'll need to render your static block on another .phtml file that is loaded on the same page and then use jQuery append to move it where you want it to display.

jQuery('#destinationContainerId').append(jQuery('#staticBlockId'));

Not the answer you're looking for? Browse other questions tagged or ask your own question.