Render HTML by changing modifying site/snippets/blocks/heading.php not working (kirby 4.6.1)

Hello all,

I want to render HTML content inside the standard heading block. Thus, I created a site/snippets/blocks/heading.php, and changed the code (after finding html() | Kirby CMS) from

<<?= $level = $block->level()->or('h2') ?>><?= $block->text() ?></<?= $level ?>>

to

<<?= $level = $block->level()->or('h2') ?>><?= $block->html() ?></<?= $level ?>>

But now, nothing gets rendered anymore in the frontend.

I even tried

<?= $block->text()->html() ?>

which replaces <span>content</span> with &lt;span&gt;content&lt;/span&gt; in the frontend.

When tried it the other way around

<?= $block->html()->text() ?>

nothing gets rendered as well.

I’m a little bit lost, because I don’t quiet understand, what I’m doing wrong concerning the documentation. I’m using the headline block inside a „layout“ element, if this is helpful.

Any help is highly appreciated :crossed_fingers:

html() is a field method that you need to call on the field inside the block, in this case text is your field. But the html method does not render html, but converts a string to an html-safe string.

Ok, but how do I achieve the result that I want? I tried

<?= html($block->text()) ?>

but with the same output of replacing <span>content</span> with &lt;span&gt;content&lt;/span&gt; (which was mentioned here Allow HTML in block headline element)

(Sorry if this may be a simple question, but I don’t really have an idea for a solution)

Right, this does the same as the field method. the problem is that any html you put into the writer field (which is used for the headings) is escaped to html entities, no matter if you call html() on it or not.

You probably need a custom writer mark for this: Writer marks/nodes | Kirby CMS, or you would need a custom method that converts html entities to html. But actually, putting html into a headline actually also displays the spans in the Panel, which is probably not what you want.