Logo Text Blaze
  • Products
    • Text Blaze
      Snippets and templates
    • AI Blaze
      AI writing and editing
    • Data Blaze
      Tables and sheets
    Downloads
    • Add to Chrome
    • Windows app
    • MacOS app
  • By function
    • Support & operations
    • Sales
    • Healthcare
    • Education
    • Recruiting
    • Marketing
    Business
    • For teams
  • Resources
    • Documentation
    • Community forum
    • Gallery
    • Contact us
  • Pricing

Documentation

No search results

Text Blaze

Loading...

Data Blaze

Loading...

Community Forums

Loading...
Add to Chrome –  It's Free! Go to Dashboard ›
Docs > Commands
  • Guides
    • Quick Start
    • Sharing Snippet Folders
    • Dynamic Commands
    • Date and Time
    • Autopilot
    • Forms
    • Formulas
    • Rules & Validation
    • Tables in Snippets
    • Connect Other Apps
    • Tidying Whitespace
    • Lists
    • Read Data from Websites
    • Teams and Organizations
  • Tutorial Videos
  • Gallery
  • Frequently Asked Questions
  • Formula Reference
  • Dynamic Commands
    • Using Dynamic Commands
    • {=} (Formula Command)
    • {button}
    • {click}
    • {clipboard}
    • {cursor}
    • {error}
    • {formdate}
    • {formmenu}
    • {formparagraph}
    • {formtext}
    • {formtoggle}
    • {if}
    • {import}
    • {key}
    • {link}
    • {note}
    • {repeat}
    • {run}
    • {site}
    • {snippet}
    • {time}
    • {user}
    • {wait}
  • Connected Snippets
    • Connected Snippets Overview
    • {image}
    • {urlload}
    • {urlsend}
    • {dbselect}
    • {dbinsert}
    • {dbupdate}
    • {dbdelete}
  • Command Packs
    • Capitalize
    • Gmail
    • LinkedIn
    • Randomize
Commands

{if}

Summary: Conditionally includes content in the snippet.
Sample Usage
You were born in the year: {formmenu: name=birthyear; 1980; 1985; default=1990; 1995; 2000; 2005; 2010; 2015}.

{if: {time: YYYY; locale=en} - birthyear >= 18; trim=left} Welcome to our service!{else} Sorry! Since you are under 18 years old, you cannot use our service.{endif}

{formtext: name=x; default=10} {if: x > y}is greater than{elseif: x < y}is less than{else}is equal to{endif} {formtext: name=y; default=5}
_

Quick Overview Video

Settings


Setting NameTypeDescription
PositionalformulaThe condition to test. Must evaluate to yes or no.
General Command Settings
trimyes/no/left/rightIf 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.

The {if} command lets you conditionally include or exclude content based on a condition. That condition is a Text Blaze Formula that must evaluate to either yes or no.

Everything within the {if} command and the required {endif} command will be inserted if the condition evaluates to yes.

Note the use of {time: YYYY; locale=en} to get the current year in the if command in the example at the top of the page. This allows the snippet to automatically update the check when Jan 1 passes without you having to update it manually.

The locale=en setting ensures the year number will be printed out in the Western formatting of 2017 or 2018 which is required for use in the if command. Some locales have other types of number formatting. You may omit this if your locale has Western number formatting.

See also the {=} (Formula Command) command and the {repeat} command for additional tools to help you build dynamic snippets.

The required {endif} command

The if command is similar to the {note} command in that the closing command must be present. In this case, it's the {endif} command.

Everything inside of these two commands will or will not get rendered depending on the output of the condition, the if command's positional setting.

The trim setting is useful for removing whitespace around the if, elseif, else, and endif commands. See the whitespace guide to learn more.

The optional {else} command

What if you would like to do something different if the condition evaluates to no?

In that case, you have access to an {else} command. The {else} command must be placed within the starting if command and the closing {endif} command.

There can only be one {else} command.

Here's an example:

Else example

Customer: "I'd like a {formmenu: name=cappuccinoSize; small; regular} cappuccino please"

Server: {if: cappuccinoSize = "small"}"Not looking for much caffeine today? {else: trim=right} "Wow, that's adventurous... {endif: trim=right} Enjoy your {=cappuccinoSize} cappucino."

_

Try it out

  • Try changing the {formmenu} command's value above and notice which part of the if command gets rendered.

Multiple if conditions with the optional {elseif} command

It's possible to test for multiple conditions with the help of the {elseif} command.

Similar to the {if} command, the {elseif} also takes a condition as its positional setting that is a Blaze Formula.

Also, just like the {else} command, they must be placed within the starting if command and the ending {endif} command.

You can have multiple {elseif} commands.

Here's an example:

Sample
{formmenu: one; two; three; four; five; six; name=number}

{if: number = "one"; trim=right} The number one. {elseif: number = "two"; trim=yes} The number two. {elseif: number = "three"; trim=yes} The number three. {else: trim=yes} It's neither one, nor two, nor three. It's some other number. {endif: trim=yes}
_

Here's what we're telling Text Blaze in the snippet above:

  1. If the form name called number contains the text "one", then give us the text "The number one"
  2. If the above isn't true, check whether it contains the text "two".
  3. If the above is true, then give us the text "The number two". If not, check whether it contains the text "three".

And so on.

At the very end, you'll need to end with an {endif} command. The {endif} command is always placed at the very end.

If the initial if conditional evaluates to no, Text Blaze will look for the next {elseif} command and evaluate its condition. It evaluates to yes, its contents will be shown, otherwise, Text Blaze will move on to the next {elseif}.

If all {elseif} commands within the if command are evaluated to no and there is an {else} command, the contents of the {else} command will be shown. The following examples illustrate the use of {elseif} and {else}.

{elseif} Example

Value: {formtext: name=val; default=10} (try changing to -5 or 20)

The number is {if: val >= 0}positive{else}negative{endif}

To be more precise it is {if: val > 0}positive{elseif: val < 0}negative{else}zero{endif}

Also, it is {if: val < -10}less than -10{elseif: val < 0}between -10 and 0{elseif: val <= 10}between 0 and 10{else}greater than 10{endif}

_

Dynamic content using the if command

Text Blaze becomes incredibly powerful when you start combining different commands like {formmenu}, {if} and {import}.

For this example, try saving the following three snippets below into your Text Blaze dashboard. This will help you understand better how Text Blaze uses these functions by seeing them in action.

To copy the snippet examples to your dashboard, click the “Copy to Text Blaze” button in the top right of the interactive snippet.

First, save the snippet below and give it the shortcut /example1.

/example1
These are the contents of the first snippet.

There can be anything in here, including a formtext field like the one below:

{formtext}
_

Now, save this second snippet below and give it the shortcut /example2.

/example2
These are the contents of the second snippet.

There can be anything in here, including a formparagraph field like the one below:

{formparagraph}
_

Finally, save this third snippet below and give it any shortcut you please.

Sample
{formmenu: name=options; Example 1; Example 2}

{if: options = "Example 1"}{import: /example1}{else}{import: /example2}{endif}
_

Now try running the third snippet somewhere in a text field.

Depending on the option you choose in the drop-down menu, Text Blaze will give you the contents of the respective snippet.

Now here's how that works.

  1. We created a drop-down menu with {formmenu} and gave it two options – Example 1 and Example 2. We also gave it the name "options".
  2. We created an if command and gave it the following instructions:
    • If the form name called options is equal to "Example 1", then you should import the contents of the snippet with the shortcut /example1
    • If the above is not true, then you should import the contents of the snippet with the shortcut /example2 (that's where the {else} command comes in).

You don't have to use an {import} command when using {if} commands, but they can help you better manage your snippets.

About

Plans and Pricing
Sharing Snippets
Text Blaze for Business
Forms
Autopilot
Dynamic Commands
Command Packs
Text Blaze for Windows
Text Blaze for macOS

Support

Get Started with Text Blaze
Contact Us
Documentation
Community Forum
Blog
Gallery
Engineering Blog

Solution for

Business
Customer Support
Recruiters
Education
Healthcare
Sales
Property Managers
AI

Other

Privacy Policy
Terms of Service
Open Source Licenses
Affiliate
© Blaze Today Inc