Getting a field's name

Hello all,

I’m new to HubSpot/HubL and I’m trying to build my first module (as a learning activity).

The issue I’m having was brought up on https://community.hubspot.com/t5/CMS-Development/Get-form-fields-name-through-Hubl/m-p/297619#M14014 - HOWEVER it seems that at the time (2019) it was just not possible to access a field’s name like that?

I wonder if this changed (couldn’t find anything online so far)? So I have a group and what I’m trying to achieve is getting the field’s name since I’ll be using it as part of the name of a class.

EDIT: The field is of type URL (not sure if this will make a huge difference?)

Something like

{% for i in module.field_group %}
 <span class="prefix-{{i.name}}"></span>
{% endfor %}

This is obviously not exactly my use-case, but it sums it up nicely. I want the name of the field, as estated on “HubL variable name” on the Design Tools fields section (to the right). So this is a meta-data thing.

Thank you all!

The link you shared is about getting the names of fields from a form used in a module not the name of module fields themselves. To get the name you can use a key, val for loop; key being the field name (don’t forget to add .items() to the end of the group variable as this is what makes it possible to iterrate through the keys).

{% for key, val in module.field_group.items() %}
 <span class="prefix-{{ key }}"></span>
{% endfor %}

Thank you very much! I was missing the .items() at the end, which seemed to be returning only the values. P.S.: It (logically) also worked as

{% for i in module.field_group.items() %}
 <span class="prefix-{{ i.key }}"></span>
{% endfor %}