Can an imported snippet have conditions based on what snippet is importing it

I'm trying to modularize my snippets more to streamline their appearance (so each one isn't too complex and long) and so I only have to change things in one place when I need to make changes. (I didn't know this would be a good practice when I started in TB a couple years ago, so it's a big project.)

I have several snippets for which a user selects from a dropdown list of options. Let's say there are 10 options total, but any given snippet will only show about half of those based on its use case.

Can my imported snippet have all the options, but if it's imported into snippet A, only certain of them show up, and if imported into snippet B, a different selection of them will show up?

(This is sort of related to my earlier question about conditionally including elements in a formmenu. Ideally the elements in this drop-down menu would appear based on a combo of conditions pulled from Data Blaze within the main snippet as well as based on which snippet they're being used in. This is making my brain hurt though.)

Hi @megan.gendell,

Can you please share an example snippet reproducing the issue? Currently, I think I am not able to understand the issue properly.

Thanks

Hi! I do believe I understand your question, as I do believe I have created a somewhat similar usecase.

As an example, you have a snippet for /invoice which you want to import. In the /invoice snippet, there are 6 options, where the first 3 should be available\visible if the snippet triggered was /hey and the last 3 should be available\visible if the snippet triggered was /hola

I'll attach a simple version of this here - btw the imported snippet won't function on it's own this way, you have to import it.

{if: triggersnippet = "Hey"}{formtoggle: name=1}opt 1{endformtoggle}
{formtoggle: name=2}opt 2{endformtoggle}
{formtoggle: name=3}opt 3{endformtoggle}{elseif: triggersnippet = "Hola"}
{formtoggle: name=4}opt 4{endformtoggle}
{formtoggle: name=5}opt 5{endformtoggle}
{formtoggle: name=6}opt 6{endformtoggle}{endif}

{triggersnippet="Hey"}{import: /invoice}

{triggersnippet="Hola"}{import: /invoice}

2 Likes

I think what @benjamin.tolfsen suggested will work (though I'm using a drop-down with values, not toggles), but I need to play around with it a bit more. Also it's so complex (for me) that I'm not sure it's worth figuring out.

This is perhaps a clearer description of what I'm aiming for:

Goal:
Snippet A contains all the info to populate, control, and insert a drop-down. There are four total possible values for the drop-down, all supplied here.
Snippet A is imported into multiple main snippets (Snippets B, C, and D).
Once Snippet B is imported, its drop-down contains values based on a combo of factors:
1: the name of Snippet B, C, or D, each of which filters out one of the four values so it does not appear in the drop-down
2. conditions in the row the user selects from Data Blaze in the main Snippet B, C, or D, which may filter out another one of the original four values, leaving two values to show in the drop-down.

Hey again,

I'm not too sure about the second filter, but the first one should be something like this

{if: triggersnippet = "Hey"}{list=["A", "B", "C"]}
{elseif: triggersnippet = "Hola"}{list=["B", "C", "D"]}{endif}
{formmenu: values={=list}}

1 Like