Solved

How can I pull product title into HTML using Liquid code?

Dan_GRHF
Excursionist
15 1 2

Hello,

I am trying to pull in some code from an order into an html file automatically. Sample below. Most of it is pulling in but I can't seem to get the Prodcut Title to pull in despite trying various combinations.

Anyone providing me insight?

<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">${{ donation_amount }}0</p>
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ order['name'] }}</p>
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ order['created_at'] }}</p>
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ order['created_at'] }}</p>
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ shop['city'] }}</p>
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ order['title'] }}</p>

 It is specifically the last line about that isn't working for me. I have tried line_item.title. Removing the [ ] etc. 

Accepted Solution (1)

tewe
Shopify Partner
244 46 102

This is an accepted solution.

Hi @Dan_GRHF,

the order has line_items. Each line_item might be connected to a product. So to go through all products in a order use

 
{%- for line_item in order.line_items -%}
{{ line_item.product.title }}

 

If you want to consider only the first product your line should read somehow like

 

<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ order.line_items[0].product.title }}</p>

 

see https://shopify.dev/docs/themes/liquid/reference/objects/order#order-line_items.

Regards
Thomas

• Was my reply helpful? Click Like to let me know!
• Was your question answered? Mark it as an Accepted Solution
• Check out our Price Updater App

View solution in original post

Replies 2 (2)

tewe
Shopify Partner
244 46 102

This is an accepted solution.

Hi @Dan_GRHF,

the order has line_items. Each line_item might be connected to a product. So to go through all products in a order use

 
{%- for line_item in order.line_items -%}
{{ line_item.product.title }}

 

If you want to consider only the first product your line should read somehow like

 

<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ order.line_items[0].product.title }}</p>

 

see https://shopify.dev/docs/themes/liquid/reference/objects/order#order-line_items.

Regards
Thomas

• Was my reply helpful? Click Like to let me know!
• Was your question answered? Mark it as an Accepted Solution
• Check out our Price Updater App
Dan_GRHF
Excursionist
15 1 2

Thanks @tewe 

I am totally not a developer and was just trying to get this to work for our site so your solution helped. I was able to pull it in with

 

{% for line_item in order.line_items %}
{{ line_item.title }}
{% endfor %}