Print select option value in modular page

first-time

#1

Hi everyone,

I’ve added a select field in one modular yml with some options. With the value_only: true option I managed to display the value instead of the key in admin panel. Now how can I display the same value in the frontend? Doing element.field return the key instead of the value.

Here the specific blueprint

.footer:
              type: select
              label: Footer
              label: Choose the feature
              value_only: true
              options:
                ciao: ciao
                come: Come
                stai: stai?

Here the TWIG template part

{% if feature.footer %}
  <h2>{{ feature.footer.name }}</h2>
{% endif %}

Ty for the support.


#2

hi @matteoredz

Interresting question :wink:

i think value_only is only for the array field.

i test in my page blueprint i use Antimatter blog.yaml

            header.test:
                type: select
                label: 'Choose the feature'
                validate:
                options:
                    ciao: ciao bella
                    come: Come va
                    stai: Come stai?

so in in front matter the value saved is test: stai for instance

Then i retrieve the select field in order to have an array then i check if my page.header.test equal key if so i print the value associated to that key

{% set select = page.blueprints.form.fields.tabs.fields.blog.fields['header.test'].options %}

{% for  key,value  in select %}
  {% if page.header.test == key %}
   {{value}}
  {% endif %}
{% endfor %}

So to retrieve the correct select option array with
{% set select = page.blueprints.form.fields.tabs.fields.blog.fields['header.test'].options %}
you have to adapt your ‘path’ in my example page.blueprints.form.fields.tabs.fields.blog.fields['header.test']

Maybe there is another solution

Hope that helps !