Render code block from Blocks Editor as HTML and not in <pre> tag

Hey all,

Is it possible to render code from the blocks editor as the code itself and not as a snippet?

My blueprint:

        label: HTML blocks
        type: blocks
          - code

Using it my template:

<?= $site->html_blocks()->toBlocks()->shuffle()->first(); ?>

At the moment, it is displayed as a code block, but I am trying to get it to render as the HTML itself. I have tried this as well:

<?= $site->html_blocks()->toBlocks()->shuffle()->first()->html(); ?>

But it returns empty. Thanks :slight_smile:

What do you mean? Like execute PHP or JS?

It would just be an HTML snippet, but at the moment, it gets rendered like this (in a p tag if using a text blocks field, in a pre tag if I use the code blocks field):

Screen Shot 2021-04-16 at 5.23.48 PM

Would it be possible to have it rendered as the actual HTML element?

Just html in a code block would be possible if you render the code block without the pre/code tags and without sending it through the html method, so that you code block snippet only contains:

<?= $block->code() ?>