Skip to main content

Conditionals

Usage

{{{? <condition> }}}
if output
{{{?? <else-if-condition> }}}
else if output
{{{??}}}
else output
{{{?}}}

Examples

Using a if statement

Take this template below that is using a block if statement to conditionally render an css import when the css answer is true.

Dot Template
import React from 'react';
{{{? tps.answers.css }}}
import "styles.css";
{{{?}}}
Result
null

Now when css is false, no output will be displayed.

Result
null

Using else statements

Take this template that is using a block if-else statement to conditionally render a import statement. If cssLang is modules, it will render an import statement for CSS modules; otherwise, it will render a normal CSS import statement.

Dot Template
import React from 'react';
{{{? tps.answers.cssLang === 'modules'}}}
import styles from './{{= tps.name}}.css';
{{{??}}}
import './{{= tps.name}}.css';
{{{?}}}
Result
null

Now when cssLang is not modules, we will get a normal CSS import statement.

Result
null

Using else if statements

Take this template that is using a block else-if statement to conditonally render a import statement. If cssLang is modules, it will render an import statement for CSS modules. Else if css is true, it will render a CSS import statement. Otherwise it will render nothing.

Dot Template
import React from 'react';
{{{? tps.answers.cssLang === 'modules'}}}
import styles from './{{= tps.name}}.css';
{{{?? tps.answers.css }}}
import './{{= tps.name}}.css';
{{{?}}}
Result
null

Now when cssLang is not modules and css is true, you will get a normal css import statement.

Result
null

Lastly when cssLang is not modules and css is false, you will get no rendered output.

Result
null