Metaobject value rendering with json code

Solved

Metaobject value rendering with json code

roving-condor
Tourist
7 2 1

Hi,

 

I have a metaobject in a liquid section on my page that is displaying single-line text as expected BUT I have a field with richtext that is rendering with some code wrapped around my dynamic content.

 

I tried adding a '{... .value | richtext }' to my metaobject value without luck. 

 

Here is my code in the liquid section:

<div class="content-container">
  {% if page.metafields.custom.ja_faq %}
  {% assign testvariable = page.metafields.custom.ja_faq.value %}
    
    <div class="intro-content">
        <h2>{{ testvariable.heading }}</h2>
      
        <div>
            {{ testvariable.paragraph.value | richtext }}
        </div>
    </div>
    
  {% endif %}
  </div>

 

Here is how it's rendering:

Screenshot 2025-02-19 151329.png

 

Appreciate the help!

 

Accepted Solution (1)

roving-condor
Tourist
7 2 1

This is an accepted solution.

Ok I finally figured this out. The solutions was to replace

{{ testvariable.paragraph.value | richtext }}

with

{{ faq.answer | metafield_tag }}

 

The " | metafield_tag" filter automatically converts Portable Text JSON into valid HTML and  the filter " | richtext" is used for older rich text formats but does not properly handle the new structured content format.

 

View solution in original post

Reply 1 (1)

roving-condor
Tourist
7 2 1

This is an accepted solution.

Ok I finally figured this out. The solutions was to replace

{{ testvariable.paragraph.value | richtext }}

with

{{ faq.answer | metafield_tag }}

 

The " | metafield_tag" filter automatically converts Portable Text JSON into valid HTML and  the filter " | richtext" is used for older rich text formats but does not properly handle the new structured content format.