{formtoggle}
Sample Usage
{formtoggle: name=Thank You; default=no}Thank you so much for your message.{endformtoggle}
[Message Contents]
{formtoggle: name=Call Me; default=yes}Please call anytime.{endformtoggle}
-Joe
Settings
Setting Name Type Description General Form Settings name text Name used for labels and data bindings. default – The default value for the form field. formatter function Formats the value of the field before snippet insertion. General Command Settings trim yes/no/left/right If yes
whitespace is removed before and after the command. If left
, only whitespace to the left is removed. If right
, only whitespace to the right is removed.
Setting Name | Type | Description |
---|---|---|
General Form Settings | ||
name | text | Name used for labels and data bindings. |
default | – | The default value for the form field. |
formatter | function | Formats the value of the field before snippet insertion. |
General Command Settings | ||
trim | yes/no/left/right | If yes whitespace is removed before and after the command. If left , only whitespace to the left is removed. If right , only whitespace to the right is removed. |
To learn more about form commands and their capabilities, see the forms guide.
Toggles allow you to selectively hide and show parts of your snippet. If a toggle is unchecked, everything between the {formtoggle}
and {endformtoggle}
commands will be hidden.
This command is similar to the {if} command, but the {if}
command uses formulas to dynamically include or exclude content.
The optional {endformtoggle} command
The {endformtoggle}
is optional and if omitted, yes
or no
will be shown when the snippet is inserted based on the value of the toggle's value.
You may change the output using the optional formatter
setting. The formatter
setting takes a function where the first parameter is the value of the toggle, either yes
or no
.
The following example illustrates this (you will need to copy it into Text Blaze and trigger the snippet to see it in practice).
Age: {formmenu: 0-20; 20-40; 40-60; 60-80; 80+}
Marital Status: {formtoggle: name=Married; formatter=(value) -> "Married" if value else "Not Married"}
The above snippet will output Married
instead of yes
, or Not Married
if the toggle's value is no
.
Click here to learn more about the formatter function available to you.
{formtoggle} and whitespace
With multiline commands like {if} or {formtoggle}
you generally want to have trailing or leading new lines to be within the command. This can be counterintuitive as it's generally not how you would write the snippet by default.
This prevents multiple extraneous newlines from showing up in your snippets. Here's an example demonstrating the issue:
{formtoggle: name=Married}You are married{endformtoggle} {formtoggle: name=Young}You are young{endformtoggle} {formtoggle: name=Tall}You are tall{endformtoggle}
A Better Way The formtoggle commands have their newline within the toggle.
{formtoggle: name=Married}You are married {endformtoggle}{formtoggle: name=Young}You are young {endformtoggle}{formtoggle: name=Tall}You are tall{endformtoggle}
To learn more about why this happens and how Text Blaze manages whitespace in your snippets, see the whitespace guide.