Is there an easy way to check if the first letter in .Title
is a vowel and then conditionally apply an instead of a?
Example"
- An Apple
- A Banana
This is what I’ve got so far:
{{$vowels := print "a"}}
{{cond (in (index (split (lower .Title) "") 0) $vowels) "an" "a" }}
This works, but if I add the other vowels and make an array, it stops working.
{{$vowels := slice "a" "e" "i" "o" "u"}}
{{cond (in (index (split (lower .Title) "") 0) $vowels) "an" "a" }}
I believe I need to range
over $vowels
to make this work, but I’m thinking there is a smarter way. I know there are singularize
/pluralize
functions. Is there something similar for this use case? How would you solve this?