Why are items duplicating in my Klaviyo email template?

Hi Guys! I’m trying to use Klaviyo app for Shopify, and I have a list of items in a e-mail with liquid that are being displayed duplicated. I need some help in identifying why is it duplicated. The e-mail template code is below:

<table>

	
		
			
			<table>

				
					
						
						

						<table>

							
								<tr>

									<td>

 

</td>

								</tr>

								
									
                    {% for item in event.extra.fulfillments.0.line_items -%}
                      {%- for line_item in event.extra.line_items -%}
                        {%- if line_item.product_id == item.product_id %}
									
                      {% endif -%}
                         {%- endfor %}
                            {%- endfor %}
										<tr>

											<td>

ITEMS

										</tr>

										
											
											<table>

												
													
														<td>
														<td>

														<table>

															
																<tr>

																	<td>

{{ line_item.product.title }}

																</tr>

																<tr>

																	<td>

{{ line_item.variant_title }}

																</tr>

																<tr>

																	<td>

Quantity: {{ line_item.quantity | floatformat: 0 - }}

																	${{ line_item.price | floatformat: 2 }}
																</tr>

															
														</table>
														
													
												
											</table>
											
										</table></table>

there is this { % for % } that I’m not getting if it’s correct or not

To fix this issue, you need to close the nested {% for %} loop after the closing </tr> tag.

Here’s the modified code with the proper loop closure:

{% for item in event.extra.fulfillments.0.line_items -%}
  {%- for line_item in event.extra.line_items -%}
    {%- if line_item.product_id == item.product_id %}
      <table>

        
          <tr>

            <td>

ITEMS

</td>

          </tr>

          
            
              <table>

                
                  
                    <td>

                      
                    

</td>

                    <td>

 

</td>

                    
                      <table>

                        
                          <tr>

                            <td>

{{ line_item.product.title }}

</td>

                          </tr>

                          <tr>

                            <td>

{{ line_item.variant_title }}

</td>

                          </tr>

                          <tr>

                            <td>

Quantity: {{ line_item.quantity | floatformat: 0 }}

                            ${{ line_item.price | floatformat: 2 }}

</td>

                          </tr>

                        
                      </table>
                    
                  
                
              </table>
            
          
        
      </table>
    {% endif %}
  {%- endfor %}
{%- endfor %}
1 Like

I’ll try it! Thank you very much!