<p>You could make a macro and use that as a "shortcut":</p>

<pre><code>{% macro optionLabel(fieldHandle, optionValue) %}

    {%- set field = craft.fields.getFieldbyHandle(fieldHandle) %}
    {%- for option in field.settings.options %}
        {%- if option.value == optionValue %}
            {{- option.label }}
        {%- endif %}
    {%- endfor %}

{%- endmacro %}
{% import _self as macros %}

&lt;h3&gt;{{ macros.optionLabel('newsType', 'newsValue') }}&lt;/h3&gt; 
</code></pre>

CC BY-SA 3.0
2015-10-06T11:53:18.937Z
Interesting yes, I did not know about twig macros yet.
migmaker
CC BY-SA 3.0
2015-10-06T10:32:06.360Z
2015-10-06T10:32:06.360Z
carlcs
<p>If you just want to get the selected radio button’s label, in the context of an existing entry, you can do this:</p>

<pre class="lang-html prettyprint-override"><code>{% if entry.newsType|length %}
    &lt;h3 class="news-type"&gt;{{ entry.newsType.label }}&lt;/h3&gt;
{% endif %}
</code></pre>

<p>(Documented here: <a href="http://buildwithcraft.com/docs/radio-buttons-fields#templating" rel="nofollow">http://buildwithcraft.com/docs/radio-buttons-fields#templating</a>)</p>

CC BY-SA 3.0
2015-10-08T06:15:05.067Z
Thx Brandon but thats the problem: I am not in the existing entry context : I have an entry type filter, I want to display the entry type (radio buttons) label that I am filtering on (from craft.request.segment(2)).
migmaker
CC BY-SA 3.0
2015-10-08T13:16:30.873Z
In that case the other answer is your best bet :)
Brandon Kelly
CC BY-SA 3.0
2015-10-06T17:10:20.870Z
2015-10-06T17:10:20.870Z
Brandon Kelly
<p>Ok I know how to list radio buttons and use it to display a particular value:  </p>

<pre><code>{% set newsType = craft.fields.getFieldbyHandle('newsType') %}
{% for option in newsType.settings.options %}
    {% if option.value == 'newsValue' %}
        &lt;h3 class="news-type"&gt;{{  option.label }}&lt;/h3&gt;
    {% endif %}
{% endfor %}
</code></pre>

<p>(I am not in an existing entry context.)
So I would like to know if there is a shortcut to directly get this label from the value? Like that syntax :</p>

<pre><code>{% set newsTypeLabel = craft.fields.getFieldbyHandle('newsType').option('newsValue').label) %}
</code></pre>

<fieldtypes>
Get label from value in radio buttons list fieldtype
# Get label from value in radio buttons list fieldtype

(Asked by: username_0 on 2015-10-06)

Ok I know how to list radio buttons and use it to display a particular value:  
{% set newsType = craft.fields.getFieldbyHandle('newsType') %}
{% for option in newsType.settings.options %}
    {% if option.value == 'newsValue' %}
        {{  option.label }}
    {% endif %}
{% endfor %}

(I am not in an existing entry context.)
So I would like to know if there is a shortcut to directly get this label from the value? Like that syntax :
{% set newsTypeLabel = craft.fields.getFieldbyHandle('newsType').option('newsValue').label) %}

**Tags:** fieldtypes

---

## 2 answers

### Answer by username_1 on 2015-10-06. Score: 4 | Accepted answer

You could make a macro and use that as a "shortcut":
{% macro optionLabel(fieldHandle, optionValue) %}

    {%- set field = craft.fields.getFieldbyHandle(fieldHandle) %}
    {%- for option in field.settings.options %}
        {%- if option.value == optionValue %}
            {{- option.label }}
        {%- endif %}
    {%- endfor %}

{%- endmacro %}
{% import _self as macros %}

{{ macros.optionLabel('newsType', 'newsValue') }}

> **Comments:**
> **username_0**: Interesting yes, I did not know about twig macros yet.  

---

### Answer by username_2 on 2015-10-06. Score: 1

If you just want to get the selected radio button’s label, in the context of an existing entry, you can do this:
{% if entry.newsType|length %}
    {{ entry.newsType.label }}
{% endif %}

(Documented here: http://buildwithcraft.com/docs/radio-buttons-fields#templating)

> **Comments:**
> **username_0**: Thx Brandon but thats the problem: I am not in the existing entry context : I have an entry type filter, I want to display the entry type (radio buttons) label that I am filtering on (from craft.request.segment(2)).  
> **username_2**: In that case the other answer is your best bet :)  

---

