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

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?


${{ donation_amount }}0

{{ order['name'] }}

{{ order['created_at'] }}

{{ order['created_at'] }}

{{ shop['city'] }}

{{ order['title'] }}

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

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


{{ order.line_items[0].product.title }}

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

Regards
Thomas

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 %}