5

In the cart example code the selected options are displayed in an unformatted list like so:

{{ item.options|json_encode }}

I noticed that the note field text could be outputted individually like so:

{{ item.note }}

I'm looking to do the same for the select fields on my product, so if I had a list of options like the gift wrap example, how would I then output the result individually (so that I can format how I like)?

<select name="options[giftWrapped]">
  <option value="no">No gift wrap.</option>
  <option value="yes">Gift wrapped.</option>
</select>

2 Answers 2

6

Answer is the example code for the cart:

{{ item.options.giftWrapped }}
4

You can also loop through each object within the options array using:

{% for key, value in item.options %}
  {{ key }} - {{ value }}
{% endfor %}

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.