Is it possible to return the Label from a Choice field, rather than the value
I am writing a simple module where the user selects a "type" of webinar. I need to return both the value and label from this element. I couldn't find any documentation on how to do that. Is it possible?
This returns the value:
{{ module.event_type }}
I tried this and a few other iterations to return the label with no luck.
{{ module.event_type.label }}
Here's the full module code if needed. I'm simply trying to output the label itself.
<div class="event_wrapper event_type_{{ module.event_type }}">
<div class="event_left">
<p class="event_type">
{# I'm using this instead of outputting the label for the time being, but I would like it to be more flexible #}
{% if module.event_type == "live_event" %}
Creating Mindful Leaders Certification Workshop Live Event
{% elif module.event_type == 'webcast_series' %}
Creating Mindful Leaders Certification Workshop Webcast Series
{% else %}
Building Employee Resilience Webcast
{% endif %}
</p>
<h3 class="event_title"><a href="{{ module.event_link.href }}" class="event_title_link">{{ module.title }}</a></h3>
<p class="event_date_time"><span class="event_date">{{ module.event_date|datetimeformat('%B %e, %Y') }}</span>{% if module.event_time %} | <span class="event_time">{{ module.event_time }}</span>{% endif %}</p>
<div class="event_desc_wrapper {% if module.event_image.src %}has_img{% endif %}">
{% if module.event_image.src %}
<div class="event_img_cont">
<img src="{{ module.event_image.src }}" alt="{{ module.event_image.alt }}" width="{{ module.event_image.width }}" height="{{ module.event_image.height }}">
</div>
{% endif %}
<div class="event_desc">
{{ module.event_description }}
</div>
</div>
</div>
<div class="event_right">
<a href="{{ module.event_link.href }}" class="event_btn">{{ module.button_text }}</a>
</div>
</div>
Is it possible to return the Label from a Choice field, rather than the value
Chiming in that this feature should absolutely be implemented. Not sure if this has changed. Like @redbranchmedia said, you will want to use the value (which is often catered by the developer to omit spaces, punctuation, etc to avoid errors) for logic/filtering purposes and using the label for front-end display. Any CMS should have this. That's why values and labels exist.
On the page editor, the users see the Labels and they make the choice accordingly. In the Hubl code, I'm using an if statement like so to determine which option they've selected:
{% if module.event_type == "live_event" %}
What I would like to do is use Hubl to output the Label. So, if the module.event_type value is equal to "live_event", for example, the output will be the Label for that value. In this case "Creating Mindful Leaders Certification Workshop Live Event".
Is it possible to return the Label from a Choice field, rather than the value
Not a dumb question at all. I have found that when a Value is set to a sentence-like structure with spaces, punctionation, etc. it can cause issues when running if statements. Also, I'd like to be able to tweak the label as needed without changing the value and all the if statements.
When looking through the developer info on a module like this, it looks like HS only provides the value. I would recommend posting this into the ideas forum for them to also pass over the field label as well into the developer info so this would be something you can grab.