Greeting,
I am trying to figure out how to prevent output when I have an incomplete array. I think my use case is like this one, but where as they are looking at the whole array as being empty while I am requiring the whole array to be full.
My data (a page level param— in the header) is structured like (A) & (B) below. I am creating an output like the following:
<dc:contributor xsi:type="olac:role" olac:code="{{ .role | lower }}">{{- .name -}}</dc:contributor>
However I want this line to only be passed to the output when there is both .role
and .name
. I am currently using the code in ( C) to range over data like (B) an get one output per .role
. Put another way there should be 5 lines of output for (B) and zero lines of output for (A).
A.
olac_roles:
- role:
name: Susan
B.
olac_roles:
- role: researcher
name: tom
- role: speaker
name: bill
- role: annotator
name: susan
- role: transcriber
name: sally
- role: translator
name: george
C.
{{- range .Params.olac_roles -}}
<dc:contributor xsi:type="olac:role" olac:code="{{ .role | lower }}">
{{- .name -}}
</dc:contributor>
{{- end -}}
I have also tried some combinations of if
statements (and
& or
& ne
& eq
) but I’m missing something. The behavior I am seeing regardless of the details of the if
clause is that the whole output is skipped, even in cases like (B).
{{- range .Params.olac_roles -}}
{{- if and (ne .role "" ) (eq .name "" ) -}}
<dc:contributor xsi:type="olac:role" olac:code="{{ .role | lower }}">
{{- .name -}}
</dc:contributor>
{{- end -}}
{{- end -}}
any pointers are appreciated. i.e. do I want a nested where clause?