Discussions

Ask a Question
Back to All

Comparing enum value to optionLabels value in order to write correct optionLabels in template

I have a simple template with in the options a dropdown field (called Soort) with enum pdf, word, excel, powerpoint, image and archive. It has the optionLabels Pdf, Word, Excel, PowerPoint, Afbeelding and Zip-bestand.

I use the enum for constructing a Fontawesome label like 'fa-file-image'.
I use the optionLabels to have the user understand what kind of file it is (Dutch) like 'Afbeelding'.

In my template I want to render both the enum and the optionLabels of the chosen option. The result must be this:

<a href="linktoimage.jpg" download="" ><i class="far fa-file-image mr-2"></i>Download Schoolplan (Afbeelding, 333 kB)</a>

In order to achieve this I tried:

<a href="{{Upload}}" download=""><i class="far fa-file-{{Soort}} mr-2"></i>{{Title}} ({{arrayindex ../Options.fields.Links.items.fields.Soort.optionLabels @index }}, {{Size}})</a>

The arrayindex returns Pdf, so that doesn't work.

I tried stuff like:

{{#each ../Schema.properties.Links.items.properties.Soort.enum }}
    {{arrayindex ../../Options.fields.Links.items.fields.Soort.optionLabels @index }}
{{/each}}

...but that just generated a list of the optionLabels. Somehow I need to compare the value of 'Soort' with index in the enum and the index in the optionLabels.

For the time being I solved it temporary like this:

<a href="{{Upload}}" download=""><i class="far fa-file-{{Soort}} mr-2"></i>{{Title}} ({{#equal Soort "pdf"}}Pdf, {{/equal}}{{#equal Soort "word"}}Word, {{/equal}}{{#equal Soort "excel"}}Excel, {{/equal}}{{#equal Soort "powerpoint"}}Powerpoint, {{/equal}}{{#equal Soort "image"}}Afbeelding, {{/equal}}{{#equal Soort "archive"}}Zip-bestand, {{/equal}}{{Size}})</a>

...but that isn't very future-oriented.

Any ideas?
Thanks!