1

I am attempting to create a repeater list for all the items in the cart, however I am having trouble generating the title and and custom fields.

{items}
                            {exp:channel:entries channel="product" entry_id="{entry_id}"}
                            <tr>
                                <td style="width:350px"><p class="item-title">{title}</p><p>Size: Large</p></td>
                                <td style="width:75px"><input style="width: 40px;" type="text" name="items[{key}][item_qty]" value="{item_qty}" /></td>
                                <td style="width:260px"><p class="item-title">{price}</p></td>
                                <td style="width:260px"><p class="item-title">{item_subtotal}</p></td>
                                <td style="width:75px; text-align: center;"><input type="checkbox" name="remove_items[{key}]" value="1" /></td>
                            </tr>
                            {/exp:channel:entries}
                            {/items}

All the short-tags used by the store function as expected, however all the titles and custom fields will only grab the data from the newest entry and repeat.

2 Answers 2

1

A great way to solve issues like this is to {embed} the script you wish to repeat.

For example:

{items}
    {embed="cart/_items.html"}
{/items}

and within your template, eg cart/_items.html

{exp:channel:entries channel="product" entry_id="{entry_id}"}
    <tr>
        <td style="width:350px"><p class="item-title">{title}</p><p>Size: Large</p></td>
        <td style="width:75px"><input style="width: 40px;" type="text" name="items[{key}][item_qty]" value="{item_qty}" /></td>
        <td style="width:260px"><p class="item-title">{price}</p></td>
        <td style="width:260px"><p class="item-title">{item_subtotal}</p></td>
        <td style="width:75px; text-align: center;"><input type="checkbox" name="remove_items[{key}]" value="1" /></td>
    </tr>
{/exp:channel:entries}

Embedding helps to eliminate issues causes when nesting loops in Expression Engine.

See Embedding Templates within Other Templates

2
  • While that would be my usual approach in this situation Bradley, it doesn't seem to work as expected with Expresso Store. By doing to we are able to repeat the correct entries, however we lose our functional {item} and subtags that Expresso Store uses. Good advice in general for this sort of issue, but doesn't seem to work in this case.
    – JakePump
    Mar 4, 2014 at 15:18
  • Ahh valid point. I didn't think of that. Mar 5, 2014 at 3:54
1

Found what the issue was, seems obvious to me now. I was using an exp:channel:entries tag wrapped around the template to generate the fields for the page itself (just title in this case), this of course caused an issue because I was calling another exp:channel:entries tag inside of it.

In order to get around this I would need to place the entire {exp:store:checkout} -- all the stuff --{/exp:store:checkout} in its own embed, not just the 2nd {exp:channel:entries} tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.