CMS Development

redbranchmedia
Contributor | Partner
Contributor | Partner

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>
squatchcreative
Contributor

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. 

dennisedson
Community Manager
Community Manager

Is it possible to return the Label from a Choice field, rather than the value

@redbranchmedia , not sure if this is what you need.  hope it helps.  let me know if i missed the ask

https://codepen.io/billyoncetoldme/pen/rPvPNo

Thanks,

Dennis




HubSpot Community Developer ShowMake sure to subscribe to our YouTube channel
where you can find the HubSpot Community Developer Show
0 Upvotes
redbranchmedia
Contributor | Partner
Contributor | Partner

Is it possible to return the Label from a Choice field, rather than the value

Thanks for taking the time to answer, I appreciate it. 

 

Unfortunately, that's not what I'm looking for. 

 

Right now, I have the choice hubl module set up with the following labels and values. 

Label = "Creating Mindful Leaders Certification Workshop Live Event"

Value = "live_event"

 

Label = "Creating Mindful Leaders Certification Workshop Webcast Series"

Value = "webcast_series"

 

Label = "Building Employee Resilience Webcast"

Value = "webcast"

 

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". 

 

Hope that helps!

 

dennisedson
Community Manager
Community Manager

Is it possible to return the Label from a Choice field, rather than the value

@redbranchmedia, i apologize if this is a dumb question, but why not set them to the same?

Thanks,

Dennis




HubSpot Community Developer ShowMake sure to subscribe to our YouTube channel
where you can find the HubSpot Community Developer Show
0 Upvotes
redbranchmedia
Contributor | Partner
Contributor | Partner

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. 

AJLaPorte_diagr
Key Advisor

Is it possible to return the Label from a Choice field, rather than the value

Hi @redbranchmedia,

 

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. 

 

Developer Info Information here:

https://designers.hubspot.com/docs/hubl/how-to-use-developer-info-on-cos-pages

 

Image showing the dev info that you can copy paste into your post on the ideas forum if you want.

choice-value-label.jpg

redbranchmedia
Contributor | Partner
Contributor | Partner

Is it possible to return the Label from a Choice field, rather than the value

Appreciate it! Will do.