5

After the 2.3.1 upgrade, which included/enabled Page Builder, a custom section we have that loads block content and displays it now escapes the html tags so it outputs all of the html visible on the page.

This only happens to blocks after we save them with Page Builder enabled, looking in the database table cms_block before and after save the main differences are that it is now wrapped in an extra div, and the html is escaped so that <div> is saved as &lt;div&gt;. These blocks are "html" type in the new Page Builder UI, so we expect them to accept html.

The code does the following:

$block = $this->blockRepository->getById($blockId);
$content = $block->getContent();

which is then output in a template.

asked Jun 5, 2019 at 22:55

1 Answer 1

5

The Page Builder addition does some extra processing on blocks, which happens during the _toHtml() method of a Magento\Cms\Block\Block class, triggered by a FilterProvider. My fix was to inject a FilterProvider into my class, and filter the block contents so that Page Builder can do its thing:

public function __construct(
 ... some stuff...
 \Magento\Cms\Model\Template\FilterProvider $filterProvider
) {
 ... snip ...
 $this->_filterProvider = $filterProvider;
}
public function myMethod($blockId)
{
 $block = $this->blockRepository->getById($blockId);
 $content = $this->_filterProvider->getBlockFilter()->filter($block->getContent());
 return $content;
}
answered Jun 5, 2019 at 22:55
1
  • After this $content still contains escaped HTML: &lt;div&gt;test&lt;/div&gt; In database HTML markup that its wrapped inside is stored properly (< and >) Commented Jan 17, 2022 at 11:41

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.