Using menus and checkboxes to conditionally enter text

Two of the most common questions that we receive on the Text Blaze team can both be solved with the same technique. These questions are:

  1. How can I have the text my snippet is generating be customized to the specific situation I'm using it in?
  2. I've created so many snippets, each for a unique scenario but those scenarios don't differ that much. Is there an easier way to group these snippets together so I don't need to remember 50 shortcuts?

In this post, I'll demonstrate how to create your own decision tree within a snippet that will output the appropriate text based on the selections you've made. These examples are meant to be generic and easy to follow so you can use them as templates for your own snippets. If you need any assistance customizing these, don't hesitate to ask!

Important starting context
All form fields support being assigned a name. Assigning fields a name allow other commands in the snippet to evaluate what's in those fields. In all of these examples, we use the {if} command to dynamically perform different actions based on the value of other fields, reading those other fields through their names. While not shown in these examples, this also allows you to re-use the values you've put in those fields elsewhere in the snippet, through the format of {=name_of_your_field}.

Example one: output text based on the selection from a dropdown menu

{note}{formmenu: ; Option 1; Option 2; Option 3; Option 4; Option 5; name=selector}{endnote}
{if: selector==""}Please select an option from the menu to proceed{elseif: selector=="Option 1"}This text is being displayed because Option 1 is selected from the menu{elseif: selector=="Option 2"}I am the text that displays when Option 2 is selected{elseif: selector=="Option 3"}Wow, different text appears when option 3 is selected{elseif: selector=="Option 4"}You guessed it, unique text for Option 4{elseif: selector=="Option 5"}Finally, the last custom text for this dropdown menu{endif}

In this example, I have a formmenu that I've named "selector", which has a blank option and then 4 selectable options. Using an {if} statement, I can read what is being chosen from that dropdown menu and then display text based on that selection.

Notice that I am also placing the formmenu itself within a {note} and {endnote} tag. Doing this lets me see the menu when I use the snippet, but prevents the menu from being inserted as text when the snippet is used.

Example two: stringing together multiple menus to create a decision tree
This example builds on the first example. The selection from the first menu will then display a second menu. The combination of your choice in the first menu and your choice in the second menu will generate the final text. Similarly, these menus are wrapped in {note} and {endnote} tags so they're not placed in the final generated text. While this example is 2 layers deep, you can stack your conditional logic as many layers as you'd like.

My {if} statement needs to evaluate both of the fields to understand the final decision, so you'll see combinations like {if: area=="arms" AND arms=="push press"}

{note}Select focus of workout: {formmenu: arms; core; legs; back; name=area}
Select specific exercise: {if: area=="arms"}{formmenu: shoulder press; push-ups; push press; name=arms}{elseif: area=="core"}{formmenu: russian twists; hollow hold; side plank; name=core}{elseif: area=="legs"}{formmenu: step-ups; back squat; romanian deadlift; name=legs}{elseif: area=="back"}{formmenu: pull-ups; ring rows; bench press; name=back}{endif}
{if: area=="arms" AND arms=="shoulder press"}Stand with your legs firmly planted holding a barbell in front-rack position. Brace your core and raise the barbell above your head until your arms lock out, using only your arms to lift the weight.{elseif: area=="arms" AND arms=="push-ups"}Get into a high plank position. Lower your chest to the ground, keeping your hips off the floor. Make sure you keep your elbows tight to your body and don't let them flare out past 45 degrees{elseif: area=="arms" AND arms=="push press"}Stand with your feet under your hips and a barbell in front-rack position. Keeping your torso and hips square, do a 2 inch dip. When returning from the dip, use the momentum to push the barbell above your head until your arms lock out
{elseif: area=="core" AND core=="russian twists"}Sit on the ground with your legs slightly elevated and feet off the ground. With a kettlebell or a medicine ball, twist from side to side. Ensure that your torso follows the weight and you're not just moving your arms.{elseif: area=="core" AND core=="hollow hold"}Sit on the ground and raise your legs and back off the ground, so that only your lower back is touching the ground. Hold for as long as possible. Make easier by bending your knees.{elseif: area=="core" AND core=="side plank"}Stack your elbow directly beneath your shoulder and your feet one on top of the other. Lift your hips off the ground and stay in a straight line. Hold for as long as possible.
{elseif: area=="legs" AND legs=="step-ups"}Using a box at 20", 24", or 26", step up onto the box with a single leg. Bring the second leg up to the box, and then step back down. Using the foot planted on the box to raise yourself up, and avoid using the back leg to "pogo" up{elseif: area=="legs" AND legs=="back squat"}Take a barbell out of the rack and rest it on your shoulders behind your head. Squeeze your lats to create a shelf. Get your legs into squat stance, and then squat as deep as you can comfortably. Ensure your keep your head up and don't let the weight drag you forward{elseif: area=="legs" and legs=="romanian deadlift"}Starting with a barbell on the ground, give your knees a very slight bend. Then, reach down to grab the barbell by pushing your hips back, not bending your knees any further. To lift the barbell, use the strength of your hip hinge to stand up straight again. Your arms are holding the barbell, but are not used to lift the weight.
{elseif: area=="back" AND back=="pull-ups"}Reach up and grab the pull-up bar with your grip just outside of your shoulders. Pull your lats down and back into an active hang, and get your body into a hollow position. Using your back and shoulders, pull your chin above the bar. Do not try to use your biceps for the pull.{elseif: area=="back" AND back=="ring rows"}Set 2 rings to roughly the height of your hips, and then walk under them until you're as parallel to the ground as you're able to do. Using your lats, pull the rings to your chest.{elseif: area=="back" AND back=="bench press"}Lay flat on your back on a bench with the barbell just above your eyes. Pull your lats together to create a nice shelf and really brace your core. Bring the barbell down to near the bottom of your sternum, then press back up.{endif}

Pro tip: This snippet's source is long because I've typed the final text into the snippet itself. To simplify this, consider saving each final text to be generated as its own snippet, and then using the {import} command to bring it into this snippet.

Example 3: using toggle fields instead of formmenus
Maybe you want to generate text based on toggle fields instead of menus. This is just a matter of personal preference, but is also possible. Alternatively, you could also accomplish this through a formmenu set to accept multiple selection (all other examples in this post use single selection only).

{note}Select all that apply:
{formtoggle: name=Option 1} {formtoggle: name=Option 2} {formtoggle: name=Option 3} {formtoggle: name=Option 4} {formtoggle: name=Option 5} {formtoggle: name=Option 6}{endnote}

{if: `Option 1`}This text is being generated because Option 1 is selected.
{endif}{if: `Option 2`}Option 2 is checked, so this text is being generated.
{endif}{if: `Option 3`}Selecting Option 3 makes this text appear.
{endif}{if: `Option 4`}There's also some custom text for choosing Option 4.
{endif}{if: `Option 5`}Yes, even more when choosing Option 5.
{endif}{if: `Option 6`}Surprise! Choosing Option 6 gives me a place to fill out custom text: {formtext}{endif}

Pro tip: because toggle boxes are boolean (true/false, or yes/no), I don't need to define them in the style of {if: `Option 1`=="true"}, I can just use {if: `Option 1`} for true or {if: not `Option 1`} for false.