John O'Grady
John O'Grady

Reputation: 245

Twig template set select control to database value

I have a class called Offices which contains id and officeName among other attributes. I'm trying to fill a select control with all possible values for that class and then set the select control to the value for the current record (stored as customer.officeName)

                        {% for office in offices %}
                            <option value="{{ office.Id}}">{{ office.officeName}}  </option>
                              {% if %}
                                     (office.id== customer.officeName)  ? ' selected ' : ''
                                     {% endif %}



                     {% endfor %}


                </select>

Any suggestions on how I can update the above syntax to work?

Upvotes: 1

Views: 558

Answers (1)

John O&#39;Grady
John O&#39;Grady

Reputation: 245

Figured it out

this works

   {% for office in offices %}
                            <option value="{{ office.Id}}"
                            {% if (office.Id== customer.managingOffice) %}
                                     {{ 'selected'}}
                                     {% endif %}
                            >{{ office.officeName}}</option>

Upvotes: 1

Related Questions