Haribo83
Haribo83

Reputation: 165

Showing select option label from ACF using timber

I would like to be able to show the select label rather than the value when returning data from a select field in timber using ACF

I can get the list of fields by using the code below but this is all fields not the one related to the record.

{{senior.field_object('job_sector').choices|print_r}}

Upvotes: 1

Views: 1049

Answers (1)

Gchtr
Gchtr

Reputation: 2794

How did you set up your ACF field? For the Select Field you can either use the value, the label or both the value and the label as a Return Value. So I’m assuming if you returned both, that would be the easiest way to solve this.

But the following might also work, assuming that senior is a post object and job_sector is the name of the select field.

{{ senior.field_object('job_sector').choices[senior.meta('job_sector')] }}

By using senior.meta('job_sector'), you select the value, which is the key to get the label in the choices array.

Upvotes: 1

Related Questions