0

In the official documentation it explains how to let users customize user fields in the frontend, such as:

<label for="bio">Bio</label>
<textarea id="bio" name="fields[bio]">{{ currentUser.bio }}</textarea>

However I set some user profile fields that are Radio Buttons and can't find anywhere on how to output the field options in a form. I want to do something like:

<select id="radioButtons" name="fields[radioButtons]">
  {% for option in fields.profile.myRadioButtons %}
    <option value="option">{{ option | title }}</option>
  {% endfor %}
</select>

But obviously 'fields' isn't a twig variable. Is there a way to do something similar to the above?

2

You can access the field using currentUser.fieldHandle; and the 'labels' and 'values' of the field by looping through the options attribute. You can also set the selected state by checking each option for the option.selected property.

<select id="radioButtons" name="fields[myRadioButton]">
    {% for option in currentUser.myRadioButton.options %}
        <option value="{{ option.value }}" {% if option.selected %}checked{% endif %}>{{ option.label }}</option>
    {% endfor %}
</select>
1
  • Exactly what I wanted. That answers other questions I had as well. Thanks Douglas Apr 23 '15 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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