Using Kirby blocks with twig

Hey there!

I was wondering if there is a way to use the blocks field with twig. At the moment it renders the php snippets as a string including the html tags in the dom.

Using the given code from the docs:

fields:
  text:
    type: blocks

<p>hello world</p>
{{ page.text.toBlocks() }}

results in the following for me:

image

My Kirby installation is running on version 3.5.3.1 with the following plugins:

  • kirby-blurry-placeholder
  • kirby-twig
  • markdown-field

Is there a way to use the given snippets with twig? Thanks a lot in advance!

That’s because Twig by default ({{ var }}) renders the content escaped - that’s all the special characters like < encoded as &lt;, for instance. What you want is to output the HTML as it is, and that’s… checks Twig docs… with a raw filter: {{ page.text.toBlocks() | raw }}

https://twig.symfony.com/doc/3.x/filters/raw.html

That worked! Thank you!