How do you use hasPrefix with multiple values?

In the docs, the following example is given:

{{ hasPrefix "Hugo" "Hu" }}

How would you amend this if you want to use a cond function to check for multiple values?

Here’s what I’m trying to do:

{{cond (hasPrefix .Title (slice "A" "E")) "a" "an"}}

If .Title starts with an A or E, I want to output an an else if false an a.

{{- cond (in (slice "a" "e" "i" "A" "E" "I") (slicestr .Title 0 1)  ) "an" "a" }}
  1. slicestr to get first character of string.
  2. using in to check whether the character inside list (slice "a" "e" "i" "A" "E" "I")

or combine with lower to handle case-sensitive.

{{- cond (in (slice "a" "e" "i") (slicestr .Title 0 1 | lower)  ) "an" "a" }}
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.