title: How to include liquid inside javascript?
body: <p>I've been trying all day long to include this liquid code inside javascript with no luck so far..</p>
  
  <p>I'm simply trying to update a div with the cart data to show the image and name, this is what I've got.</p>
  
  <pre><code>$('.openCart').click(function(e)
  {          
      $.ajax({
          type: 'POST',
          url: '/cart/add.js',
          data: data,
          dataType: 'json',
          success: function()
          {
            {% capture content %}{% include 'addItemToCartDetails' %}{% endcapture %}
            var content = {{ content | json }};
            $("._second").html(content);
          }
      });
   });
  </code></pre>
  
  <p>Overall the following code doesn't work(simply because of the for loop, and I have no clue how to get around this..): If I remove the for loop then the code retrieves the divs and everything, besides the item data since the loop isn't working.</p>
  
  <p>This is the <code>addItemToCartDetails.liquid</code>,</p>
  
  <pre><code>{% for item in cart.items %}
  
      &lt;div class="_second_1"&gt;
        &lt;a href="{{ item.url | widivin: collections.all }}" class="cart-image"&gt;
          &lt;img width="320" src="{{ item | img_url: '700x700' }}" alt="{{ item.title | escape }}"&gt;
        &lt;/a&gt;
      &lt;/div&gt;
  
      &lt;div class="_second_2"&gt;&lt;h3&gt;Product Name&lt;/h3&gt;{{ item.product.title }}&lt;/div&gt;
  
      &lt;div class="_second_3"&gt;&lt;h3&gt;Remove Product&lt;/h3&gt;&lt;span class="clearCart"&gt;Remove&lt;/span&gt;&lt;/div&gt;
  
      &lt;div class="_second_4"&gt;&lt;h3&gt;Quantity&lt;/h3&gt;&lt;input class="quantity" type="input" name="updates[]" id="updates_{{ item.id }}" value="{{ item.quantity }}" min="0" data-id="{{ item.id }}" title="If you'd like another subscription please checkout separately" alt="If you'd like another subscription please checkout separately" disabled&gt;&lt;/div&gt;
  
      &lt;div class="_second_5"&gt;
        &lt;h3&gt;Total Price&lt;/h3&gt;
  
        &lt;div class="totalDetails"&gt;Total: {{ item.line_price | plus: 0 | money }} / month&lt;/div&gt;
  
      &lt;/div&gt;
  
      &lt;div class="_third"&gt;
        &lt;input type="submit" name="checkout" value="PROCEED TO CHECKOUT"&gt;
      &lt;/div&gt;
  
  {% endfor %}
  </code></pre>