Liquid Code Pulling into HTML

Solved
Dan_GRHF
Tourist
10 1 0

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. 

0 Likes

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

• War meine Antwort hilfreich? Hinterlasse bitte ein Like.
• Hat meine Antwort Dein Problem gelöst? Bitte akzeptiere sie als Lösung.
0 Likes
Dan_GRHF
Tourist
10 1 0

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

 

0 Likes