# [CS2] Template Operators

Operators are symbols that allow you to compare two values or combine two values.

## Comparison Operators

Many times you whether in using a ternary condition or in conditional rendering you'll want to use a comparison operator. This page documents what is available to you in the component studio templating language. These operators will return true or false.

Operator | Description | Example |

== | Equal to. Note that is not the same thing. = |
{{quantity == 5}} {{color == 'blue'}} |

!= | Not equal to. | {{quantity != 5} } {{color != 'blue'}} |

> | Greater than. | {{quantity > 2}} |

< | Less than. | {{quantity < 2}} |

>= | Greater than or equal to. | {{quantity >= 2}} |

<= | Less than or equal to. | {{quantity <= 2}} |

if else | Ternary condition. It takes 3 arguments. The first is the true value condition to validate, and then the false value. | {{true if level > 2 else false}} |

## Arithmetic Operators

Perform a mathematical calculation upon two values.

Operator | Description | Example | Result |

+ | Addition | {{1 + 1}} | 2 |

- | Subtraction | {{1 - 1}} | 0 |

* | Multiplication | {{1 * 1}} | 1 |

/ | Division | {{1 / 1}} {{5 / 2}} |
1 2.5 |

// | Division with truncation. | {{1 // 1}} {{5 // 2}} |
1 2 |

% | Modulus, the remainder after division. | {{1 % 1}} {{5 % 3}} |
1 2 |

** | The power of another number. | {{2**2}} | 4 |

## Logical Operators

Perform logic operations on values to determine a true or false value.

Operator | Description | Example | Result |

not | Not. Inverts the value. | {{not 1}} {{not 3 < 1}} |
false true |

and | And. | {{0 and 0}} {{1 and 0}} {{1 and 1}} {{ 3 > 1 and 1 > 0}} |
false false true true |

or | Or. | {{0 or 0}} {{1 or 0}} {{1 or 1}} {{ 3 > 1 or 1 > 0}} |
false true true |

if else |
Ternary. It takes 3 arguments. The first is the true value then the condition to validate, and then the false value. Note that the false value is optional. | {{ 'purple' if position == 'king' else 'white'}} {{ 'purple' if position == 'king'}} |
purple purple |

## String Operators

Use the to manipulate strings.

Operator | Description | Example | Result |

+ | Concatenate. Combines two strings together. | {{'R' + 'G' + 'B'}} {{first_name + ' ' + last_name}} |
RGB Andy Dufresne |

## Empty

When you are trying to check for a field that is empty, then you'll want to use 2 half quotes ''.

{{this_might_be_empty == ''}}

Another way to do this would be to simply put the variable in the field, as Component.Studio treats empty fields as false. So if you were to put this in the "render this layer?" field, it would work:

{{ this_might_be_empty }}

This last option will likely never come up, but it is possible that some values will be defined as 'null'. In those very rare circumstances, you can test for that by using the special keyword null without quotes like this:

this_is_null == null