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.
pamubay
2
{{- cond (in (slice "a" "e" "i" "A" "E" "I") (slicestr .Title 0 1) ) "an" "a" }}
-
slicestr
to get first character of string.
- 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
system
Closed
3
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.