0

I have Magento 2.2.3 and activated terms and conditions. And I added

{{block class="Magento\\Cms\\Block\\Block" area='frontend' block_id="agb"}} {{block class="Magento\\Cms\\Block\\Block" block_id="agb"}}

but in popup no text is shown, only above code is shown. Anyone an idea what is wrong? I use same snippet in other shop and it is working

Thanks! Martin enter image description here

asked May 4, 2018 at 8:50
2
  • Have you added static block in phtml file or CMS page ? Commented May 4, 2018 at 9:04
  • yes - and it is active Commented May 4, 2018 at 9:13

2 Answers 2

0

The agreements are rendered via knockout js, therefore you cannot add a cms block to their content, you could go and extend the agreements module to process the data before sending it to the frontend via knockout, but i would just turn things around.

Don't include a cms block inside the agreements, but include the agreements in your cms page as follows:

use the Layout/design update xml field for the cms page with something like the following:

<referenceContainer name="content">
 <block class="Magento\CheckoutAgreements\Block\Agreements" name="agb.agreement" template="Vendor_Module::html/agreements/agb.phtml" after="-" />
</referenceContainer>

and the corresponding template to insert exactly the one agreement you want:

<?php
/**
 * @var $block \Magento\CheckoutAgreements\Block\Agreements
 */
/**
 * Define agreement for display
 *
 * Copy this template if you wish to insert an agreements static content somewhere
 *
 * @var $display_agreement string - Agreement id or name
 */
$display_agreement = 'AGB';
/**
 * Process
 */
$was_found = false;
foreach ($block->getAgreements() as $agreement) {
 // Found requested agreement
 if ($agreement->getId() == $display_agreement || $agreement->getName() == $display_agreement) {
 $was_found = true;
 print '<div class="agreement_content">';
 if ($agreement->getIsHtml()) {
 /* @escapeNotVerified */
 print $agreement->getContent();
 } else {
 print nl2br($block->escapeHtml($agreement->getContent()));
 }
 print '</div>';
 }
}
if (!$was_found) {
 throw new Exception('Agreement display failed, could not find: ' + $display_agreement);
}

You can find some more info on the agreements block here: Why does getAgreements() return nothing?

answered Mar 14, 2019 at 10:35
0

agreement content is load from class Magento\CheckoutAgreements\Model\AgreementsConfigProvider protected function getAgreementsConfig()

'content' => $agreement->getIsHtml()
 ? $agreement->getContent()
 : nl2br($this->escaper->escapeHtml($agreement->getContent()))

could override using preference

use below function to get cms block content

/** @var \Magento\Framework\View\LayoutInterface */
protected $_layout;
public function __construct(\Magento\Framework\View\LayoutInterface $layout)
{
 $this->_layout = $layout;
}
public function getContent()
{
 $cmsBlockId = 1; // id of cms block to use
 return $this->_layout->createBlock('Magento\Cms\Block\Block')->setBlockId($cmsBlockId)->toHtml();
}
answered Jul 22, 2021 at 4:50
1
  • Can you specify which files to edit and where to put them to avoid core overrides? Commented Jun 23, 2023 at 11:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.