<p><code>{% for item in cart.lineItems %}</code> and <code>{% for lineItem in cart.lineItems %}</code> are the same loop - you're just assigning a different name to the iterable item! Just remove the inner loop and rename the inner variables to <code>item</code> instead of <code>lineItem</code>. Maybe I'm missing what you're trying to achieve?</p>

CC BY-SA 4.0
2020-03-06T22:07:45.580Z
That worked. I wasn't sure if they were separate elements. Thanks for clarifying. Still wrapping my head around Commerce.
glider
CC BY-SA 4.0
2020-03-06T15:01:05.747Z
2020-03-06T15:01:05.747Z
James Smith
<p>I'm trying to show custom fields on the cart but I'm missing something (and new to Commerce, so bear with me). When I output <code>{% for lineItem in cart.lineItems %}</code>  within my <code>{% for item in cart.lineItems %}</code> it outputs all the products again within the same line. How can I get the custom field to only show up on the line that is being output? </p>

<pre><code>{% set lineItemHasErrors = false %}
{% for item in cart.lineItems %}
    {% if item.hasErrors() %}
        {# if the line item has errors lets record it so we can hide totals later (since they wont make sense) #}
        {% set lineItemHasErrors = true %}
    {% endif %}
    &lt;tr class="item" {% if item.hasErrors() %}style="background-color:rgba(255, 0, 0, .1);"{% endif %}&gt;
        &lt;td&gt;
            {% for lineItem in cart.lineItems %} 

            {% if lineItem.purchasable.product.type.hasVariants %}
              {% switch lineItem.purchasable.product.type %}
                {% case "wallpaper" %}
                    {#  Only output the varHeight if the product type is wallpaper #}
                    &lt;strong&gt;{{ lineItem.description }}&lt;/strong&gt;&lt;br&gt;
                    Height: {{ lineItem.purchasable.varHeight }}
                {% default %}
                    {{ lineItem.description }}
              {% endswitch %}

            {% else %}
                {#  Non variant purchasable  #}
                &lt;strong&gt;{{ lineItem.description }}&lt;/strong&gt;

            {% endif %}

            {% endfor %}

            {% if item.options.material is defined %}
            &lt;div class="select"&gt;
              &lt;select name="lineItems[{{ item.id }}][options][material]"&gt;
                &lt;option value="no"
                        {% if item.options.material == 'PeelNStick' %}selected{% endif %}&gt;
                    Peel N Stick
                &lt;/option&gt;
                &lt;option value="yes"
                        {% if item.options.material == 'PrePasted' %}selected{% endif %}&gt;
                   Pre Pasted
                &lt;/option&gt;
              &lt;div class="select__arrow"&gt;&lt;/div&gt;
            &lt;/div&gt;
            {% endif %}

            &lt;br&gt;
            &lt;label&gt;
            &lt;input type="checkbox"
                   name="lineItems[{{ item.id }}][remove]"
                   value="1"&gt; Remove Item
            &lt;/label&gt;
        &lt;/td&gt;
        &lt;td&gt;


        &lt;td class="text-right"&gt;
            {% if not lineItemHasErrors %}
                {% if item.onSale %}
                    &lt;s&gt;Price: {{ item.price|commerceCurrency(cart.currency) }}&lt;/s&gt;
                    &lt;br&gt;
                    Sale Off: {{ item.saleAmount|commerceCurrency(cart.currency) }}
                    &lt;br&gt;
                    Sale Price {{ item.salePrice|commerceCurrency(cart.currency) }}
                    &lt;br&gt;
                    Sale Price Subtotal: {{ item.subtotal|commerceCurrency(cart.currency) }}
                    &lt;br&gt;
                {% else %}
                    Price: {{ item.price|commerceCurrency(cart.currency) }}
                    &lt;br&gt;
                    Price Subtotal: {{ item.subtotal|commerceCurrency(cart.currency) }}
                    &lt;br&gt;
                {% endif %}
            {% endif %}

            {% for sale in item.purchasable.sales %}
                {% if loop.first %}
                    Sales Applied:
                {% endif %}
                {{ sale.name }}&lt;br&gt;
            {% endfor %}
        &lt;/td&gt;
    &lt;/tr&gt;
    {% if not lineItemHasErrors %}
        {% for adjustment in item.adjustments %}
            &lt;tr class="adjustment"&gt;
                &lt;td&gt;&lt;/td&gt;
                &lt;td&gt;
                    &lt;strong&gt;{{ adjustment.type }} {{ adjustment.name }}&lt;/strong&gt;&lt;br&gt;({{ adjustment.description }}
                    )
                &lt;/td&gt;
                &lt;td class="text-right"&gt;{{ adjustment.amount|commerceCurrency(cart.currency) }}&lt;/td&gt;
            &lt;/tr&gt;
        {% endfor %}
    {% endif %}


 {% endfor %}
</code></pre>

<p><a href="https://i.sstatic.net/VOgM3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/VOgM3.png" alt="enter image description here"></a></p>

<plugin-craftcommerce><plugin-craftcommerce2>
Show custom fields on cart
# Show custom fields on cart

(Asked by: username_0 on 2020-03-06)

I'm trying to show custom fields on the cart but I'm missing something (and new to Commerce, so bear with me). When I output {% for lineItem in cart.lineItems %}  within my {% for item in cart.lineItems %} it outputs all the products again within the same line. How can I get the custom field to only show up on the line that is being output? 
{% set lineItemHasErrors = false %}
{% for item in cart.lineItems %}
    {% if item.hasErrors() %}
        {# if the line item has errors lets record it so we can hide totals later (since they wont make sense) #}
        {% set lineItemHasErrors = true %}
    {% endif %}
    
        
            {% for lineItem in cart.lineItems %} 

            {% if lineItem.purchasable.product.type.hasVariants %}
              {% switch lineItem.purchasable.product.type %}
                {% case "wallpaper" %}
                    {#  Only output the varHeight if the product type is wallpaper #}
                    {{ lineItem.description }}
                    Height: {{ lineItem.purchasable.varHeight }}
                {% default %}
                    {{ lineItem.description }}
              {% endswitch %}

            {% else %}
                {#  Non variant purchasable  #}
                {{ lineItem.description }}

            {% endif %}

            {% endfor %}

            {% if item.options.material is defined %}
            
              
                
                    Peel N Stick
                
                
                   Pre Pasted
                
              
            
            {% endif %}

            
            
             Remove Item
            
        
        


        
            {% if not lineItemHasErrors %}
                {% if item.onSale %}
                    Price: {{ item.price|commerceCurrency(cart.currency) }}
                    
                    Sale Off: {{ item.saleAmount|commerceCurrency(cart.currency) }}
                    
                    Sale Price {{ item.salePrice|commerceCurrency(cart.currency) }}
                    
                    Sale Price Subtotal: {{ item.subtotal|commerceCurrency(cart.currency) }}
                    
                {% else %}
                    Price: {{ item.price|commerceCurrency(cart.currency) }}
                    
                    Price Subtotal: {{ item.subtotal|commerceCurrency(cart.currency) }}
                    
                {% endif %}
            {% endif %}

            {% for sale in item.purchasable.sales %}
                {% if loop.first %}
                    Sales Applied:
                {% endif %}
                {{ sale.name }}
            {% endfor %}
        
    
    {% if not lineItemHasErrors %}
        {% for adjustment in item.adjustments %}
            
                
                
                    {{ adjustment.type }} {{ adjustment.name }}({{ adjustment.description }}
                    )
                
                {{ adjustment.amount|commerceCurrency(cart.currency) }}
            
        {% endfor %}
    {% endif %}


 {% endfor %}

**Tags:** plugin-craftcommerce, plugin-craftcommerce2


---

## 1 answers

### Answer by username_1 on 2020-03-06. Score: 2 | Accepted answer

`{% for item in cart.lineItems %}` and `{% for lineItem in cart.lineItems %}` are the same loop - you're just assigning a different name to the iterable item! Just remove the inner loop and rename the inner variables to `item` instead of `lineItem`. Maybe I'm missing what you're trying to achieve?

> **Comments:**
> **username_0**: That worked. I wasn't sure if they were separate elements. Thanks for clarifying. Still wrapping my head around Commerce.  

---

