I'm wondering if I can assign certain values to each dropdown selection without having to create a conditional statement for each option?
{formmenu: A;B;C; name=options}
{if: options="A"}{output="hello"}{elseif: options="B"}{output="hi"}{elseif:options="C"}{output="hey"}{endif}
{=output}
Ideally, I'd like to avoid the {IF} statements and be still able to display the desired outputs.
Great question! You can use a keyed list to avoid that:
{formmenu: A; B; C; name=options}
{mapping=["A": "hello", "B": "hi", "C": "hey"]}
{output=mapping[options]}
{=output}
1 Like
Quick as always Gaurang. Thank you so much!
1 Like
Hey Gaurang, I tried to use this method when importing snippets and it didn't work. Is there a workaround?
Can you please share your two snippets - the one that has this menu and the one you were importing?
I see your requirement now. You are trying to do dynamic imports - where a specific snippet is imported based on a particular condition. This is currently not possible to do, although it is a pending feature request.
The current {import:/mysnippet} command does not allow for variable import names such as {import:{=myvar}}. Working around this creates a lot of extra work in certain use cases, the code for which dramatically slows down TextBlaze's execution time.
For example, I have a long list of snippes with the shortcut names all prefixed with "yvfi" (e.g. "yvfiteeth", "yvfichoice", "yvfiprotein", etc.). I'd like to be able to use these in a mix-and-match fashion within the context of a repeat structure:
…
I request you to upvote it and add your use case there as well.
1 Like