Why won't my variant metafield render HTML in this code?

Solved

Why won't my variant metafield render HTML in this code?

Tim14
Shopify Partner
3 1 0

I'm trying to get a variant metafield to render HTML. It's in a capture. The variant works fine on it's own and renders HTML. Only when it's in this piece of code it fails to render. Any suggestions please?

 

<span class="delivery-message" itemprop="delivery-message">{{ variant.sku }}</span>

{% capture 'meta_data' %} {% for variant in product.variants %} {{ variant.sku | json }}: {{ variant.metafields.custom.delivery_message | json }} {% unless forloop.last %},{% endunless %} {% endfor %} {% endcapture %} <script> var metaData = { {{ meta_data }} } var selectCallback = function(variant, selector) { if (variant) { if (variant.sku != '') { $('.variant-sku').text('SKU: ' + variant.sku); $('.delivery-message').text((metaData[variant.sku])); } } else { $('.variant-sku').empty(); }
Accepted Solution (1)

Tim14
Shopify Partner
3 1 0

This is an accepted solution.

Figured it out.

 

Changed:

$('.delivery-message').text((metaData[variant.sku]));

 To:

$('.delivery-message').html((metaData[variant.sku]));

View solution in original post

Reply 1 (1)

Tim14
Shopify Partner
3 1 0

This is an accepted solution.

Figured it out.

 

Changed:

$('.delivery-message').text((metaData[variant.sku]));

 To:

$('.delivery-message').html((metaData[variant.sku]));