How do I display a Config option only when two or more other items are True or False? I tried
when: repl{{ ConfigOptionEquals "option_one" "0" }} & repl{{ ConfigOptionEquals "option_two" "0" }}
but this isn’t working as expected.
Answer:
Only show option foo
if both options are false.
- name: conditional_and
title: Conditional conditional
description: only shows up when both option_one and option_two are set to False
when: repl{{ (and (ConfigOptionEquals "option_one" "false") (ConfigOptionEquals "option_two" "false")) }}
items:
- name: foo
title: foo
type: text
default: "foo"
You can use both and
as well as or
in the when
field if you are using templating.
Here is an example config that displays labels based on which options are selected:
apiVersion: kots.io/v1beta1
kind: Config
metadata:
name: config-sample
spec:
groups:
- name: example_settings
title: My Example Config
description: Configuration to serve as an example for creating your own. See [https://kots.io/reference/v1beta1/config/](https://kots.io/reference/v1beta1/config/) for configuration docs. In this case, we provide example fields for configuring an Ingress object.
items:
- name: option-1
title: option 1
type: bool
default: "0"
- name: option-2
title: option 2
type: bool
default: "0"
- name: option-3
title: option 3
type: bool
default: "0"
- name: option-1-and-2
title: Option 1 and 2 are selected
type: label
when: repl{{ and (ConfigOptionEquals "option-1" "1") (ConfigOptionEquals "option-2" "1") }}
- name: option-1-or-3
title: Option 1 or 3 are selected
type: label
when: repl{{ or (ConfigOptionEquals "option-1" "1") (ConfigOptionEquals "option-3" "1") }}
Here is how it behaves in a deployed instance: