Members can have roles. OK, fine. But,... What if one of those roles is simply "officer" and there's another field that you're using to say which particular office they hold? I.e., after I define roles, further down in my /_config/bundles/member/fields.yaml I've got (something like):

  chapter_office_or_title:
    type: select
    display: Chapter Office or Title: 
    options:
      member: Member
      chair: Chair
      chair_elect: Chair-Elect
      vice_chair: Vice Chair
      treasurer: Treasurer
      secretary: Secretary
      abc_coordinator: ABC Coordinator
      advisor: (Advisor)

Good? OK. So, what am I really trying to do? Well, elsewhere on the site, I'm displaying a table of member info, and I just want to show someone's office or title after their name. Easy, right? Well, I would have thought so, but...

You might be tempted (as I initially was) to just grab the field and display someone's title using

{{ chapter_office_or_title|deslugify|title }}

but that doesn't do justice to that hyphen in "Chair-Elect", the capitalized entire first word in "ABC Coordinator", or those parens around "(Advisor)". (* sigh *)

I've shaken the documentation pretty hard, but so far nothing has fallen out that tells me how to reference a select fieldtype's label. Which is pretty tantalizing, as it can so easily be seen in the CP's lovely dropdown.

Well, OK, (* deep breath *) here's my present work-around (NB. wherein a simple "member" gets a blank, or no title):

{{if ((chapter_office_or_title == 'member') }}
{{ elseif (chapter_office_or_title == 'chair')}}Chair
{{ elseif (chapter_office_or_title == 'chair_elect')}}Chair-Elect
{{ elseif (chapter_office_or_title == 'vice_chair')}}Vice Chair
{{ elseif (chapter_office_or_title == 'treasurer')}}Treasurer
{{ elseif (chapter_office_or_title == 'secretary')}}Secretary
{{ elseif (chapter_office_or_title == 'marketing')}}Marketing
{{ elseif (chapter_office_or_title == 'abc_coordinator')}}ABC Coordinator
{{ elseif (chapter_office_or_title == 'advisor')}}(Advisor)
{{ else}}???
{{ endif }}

Does it work. Yes.

Do I like it. No. I hate it. It ain't DRY ("Don't Repeat Yourself"), and it will surely be a headache if the chapter offices or titles in the CP's member fieldtype ever get edited. Which is likely.

So, how would you handle this?

::scratches head::

It's conceptually an issue of "sub-roles", so if you can tell me how, I'll run right out and open a deli! (<--a little humor, eh? ;-)

Answered by Jason Varga! Go to answer.