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
-
Have you added static block in phtml file or CMS page ?Hitesh Koshti– Hitesh Koshti2018年05月04日 09:04:14 +00:00Commented May 4, 2018 at 9:04
-
yes - and it is activematin– matin2018年05月04日 09:13:49 +00:00Commented May 4, 2018 at 9:13
2 Answers 2
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?
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();
}
-
Can you specify which files to edit and where to put them to avoid core overrides?TheFrakes– TheFrakes2023年06月23日 11:42:08 +00:00Commented Jun 23, 2023 at 11:42