How can I have a choice variable with values that depends on a previous choice variable selection?

586 Views Asked by At

I am using cookiecutter to create a project template for Reveal.js presentations (just for context).

A given template has multiple themes that can be selected, but the theme list in not the same for all templates.

Is there a way to modify the theme list based on the template_name selected?

Not a valid json, but something to illustrate:

{
  "template_name": ["default", "brand"],
  "theme_name": ["default", "dark", "blue"], # if template_name == "default"
  "theme_name": ["magenta"] # if template_name == "brand"
}

Any other suggestions to accomplish that is appreciated. Thanks!

1

There are 1 best solutions below

0
On

You could make the 'switch' element a dictionary rather than a list.

dct = {
"template_name": {"default":"theme1", 
"brand":"theme2"},
"theme1": ["default", "dark", "blue"],
"theme2": ["magenta"]
}

print(dct[dct["template_name"]["default"]])
print(dct[dct["template_name"]["brand"]])

Output:

['default', 'dark', 'blue']
['magenta']