1

I have a single static Super Table Field with some Dropdown Fields. Is it possible to loop through the values instead of hardcoding each one? My hardcoded version works without problems but i think a dynamic loop is better for the future.

Here is one example: ('static' is the value of the Super Table btw.)

<li>
    <label for="fields[{{ fieldHandle }}][{{ block.id }}][fields][visibility]">Visibility:</label>
    <select name="fields[{{ fieldHandle }}][{{ block.id }}][fields][visibility]">
      <option value="privat"{% if entry.static.visibility.value == "privat" %} selected{% endif %}>Privat</option>
      <option value="public"{% if entry.static.visibility.value == "public" %} selected{% endif %}>Public</option>
    </select>
</li>

Would be great, if someone has a idea! Thanks

1 Answer 1

1

You should be able to do this in the same way as for a dropdown field in Craft as described in the docs.

Something like this should work if entry is populated:

<li>
    <label for="fields[{{ fieldHandle }}][{{ block.id }}][fields][visibility]">Visibility:</label>
    <select name="fields[{{ fieldHandle }}][{{ block.id }}][fields][visibility]">
      {% for option in entry.static.visibility.options %}
         <option value="{{ option.value }}"{% if option.selected %} selected{% endif %}>{{ option.label }}</option>
      {% endfor %}
    </select>
</li>
1
  • just that easy. Thanks!
    – Markus
    May 18, 2019 at 9:08

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.