Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-06T22:07:45.580Z
Answers.Text: That worked. I wasn't sure if they were separate elements. Thanks for clarifying. Still wrapping my head around Commerce.
Answers.UserDisplayName: glider
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-06T15:01:05.747Z
Answers.LastActivityDate: 2020-03-06T15:01:05.747Z
Answers.UserDisplayName: James Smith
Body: <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>
  
Tags: <plugin-craftcommerce><plugin-craftcommerce2>
Title: Show custom fields on cart
ThreadText: # 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 %}
      <tr class="item" {% if item.hasErrors() %}style="background-color:rgba(255, 0, 0, .1);"{% endif %}>
          <td>
              {% 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 #}
                      <strong>{{ lineItem.description }}</strong><br>
                      Height: {{ lineItem.purchasable.varHeight }}
                  {% default %}
                      {{ lineItem.description }}
                {% endswitch %}
  
              {% else %}
                  {#  Non variant purchasable  #}
                  <strong>{{ lineItem.description }}</strong>
  
              {% endif %}
  
              {% endfor %}
  
              {% if item.options.material is defined %}
              <div class="select">
                <select name="lineItems[{{ item.id }}][options][material]">
                  <option value="no"
                          {% if item.options.material == 'PeelNStick' %}selected{% endif %}>
                      Peel N Stick
                  </option>
                  <option value="yes"
                          {% if item.options.material == 'PrePasted' %}selected{% endif %}>
                     Pre Pasted
                  </option>
                <div class="select__arrow"></div>
              </div>
              {% endif %}
  
              <br>
              <label>
              <input type="checkbox"
                     name="lineItems[{{ item.id }}][remove]"
                     value="1"> Remove Item
              </label>
          </td>
          <td>
  
          <td class="text-right">
              {% if not lineItemHasErrors %}
                  {% if item.onSale %}
                      <s>Price: {{ item.price|commerceCurrency(cart.currency) }}</s>
                      <br>
                      Sale Off: {{ item.saleAmount|commerceCurrency(cart.currency) }}
                      <br>
                      Sale Price {{ item.salePrice|commerceCurrency(cart.currency) }}
                      <br>
                      Sale Price Subtotal: {{ item.subtotal|commerceCurrency(cart.currency) }}
                      <br>
                  {% else %}
                      Price: {{ item.price|commerceCurrency(cart.currency) }}
                      <br>
                      Price Subtotal: {{ item.subtotal|commerceCurrency(cart.currency) }}
                      <br>
                  {% endif %}
              {% endif %}
  
              {% for sale in item.purchasable.sales %}
                  {% if loop.first %}
                      Sales Applied:
                  {% endif %}
                  {{ sale.name }}<br>
              {% endfor %}
          </td>
      </tr>
      {% if not lineItemHasErrors %}
          {% for adjustment in item.adjustments %}
              <tr class="adjustment">
                  <td></td>
                  <td>
                      <strong>{{ adjustment.type }} {{ adjustment.name }}</strong><br>({{ adjustment.description }}
                      )
                  </td>
                  <td class="text-right">{{ adjustment.amount|commerceCurrency(cart.currency) }}</td>
              </tr>
          {% endfor %}
      {% endif %}
  
   {% endfor %}
  
  ```
  
  [![enter image description here](https://i.sstatic.net/VOgM3.png)](https://i.sstatic.net/VOgM3.png)
  
  **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.  
  
  ---
  
  