call product title variable in description

call product title variable in description

lewisfigs
Visitor
2 0 0

I've looked through the docs to try and find the answer, but it is unclear. 

I am uploading a new product list of 200 products, many have the same description except the name of the item (the shopify title). I'd like to call that title as a variable in the description using the {{ product.title }} tag, but it does not work.

I see references to the main-product.liquid code, but it's unclear what I am supposed to do there.

 

The product description HTML I'd like to use is:

<p>{{ product.title }} is a fig tree variety from AJ's Collection. We will learn more about this variety during the growing season of 2025.</p> 

 

This renders the following on the webpage:

{{ product.title }} is a fig tree variety from AJ's Collection. We will learn more about this variety during the growing season of 2025.

 

Any help would be appreciated!

Replies 3 (3)

Asad-Mahmood
Navigator
300 51 56

The issue you're experiencing is because Shopify doesn't parse Liquid variables ({{ product.title }}) within the product description field by default. The product description field is treated as static HTML, and Liquid variables are not interpreted there.

To achieve your goal, you need to modify the main-product.liquid (or equivalent) file where the product description is rendered. Here's how to resolve this:

 

{{ product.description | replace: '{{ product.title }}', product.title }}

 


This code replaces the placeholder {{ product.title }} in the description with the actual product title dynamically.



If my solution has been helpful, you can consider supporting me via Buy Me a Coffee.
Hire me: asadmahmood8470@gmail.com
WhatsApp





lewisfigs
Visitor
2 0 0

Hi @Asad-Mahmood thank you for replying. When modifying the main-product.liquid, I should 

 

replace this:

{%- when 'description' -%}
{%- if product.description != blank -%}
<div class="product__description rte quick-add-hidden" {{ block.shopify_attributes }}>
{{ product.description }}
</div>

 

with:

{%- when 'description' -%}
{%- if product.description != blank -%}
<div class="product__description rte quick-add-hidden" {{ block.shopify_attributes }}>
{{ product.description | replace: '{{ product.title }}', product.title }}
</div>

 

correct?

when I do that, I get an error: 

  • Liquid syntax error (line 197): Unexpected character ' in "{{ product.description | replace: '{{ product.title }}"
summitsoul
Excursionist
15 1 3

Hello,

did you figure out what you need to do? 

I would also like to use this for my shop.

 

Thank you!