# [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
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.61276877,"math_prob":0.9749471,"size":2777,"snap":"2023-40-2023-50","text_gpt3_token_len":832,"char_repetition_ratio":0.12008655,"word_repetition_ratio":0.059642147,"special_character_ratio":0.3424559,"punctuation_ratio":0.100823045,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96105003,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-21T10:11:22Z\",\"WARC-Record-ID\":\"<urn:uuid:331af261-662d-42e9-8b69-d48ae0d9c553>\",\"Content-Length\":\"19702\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8d35754c-1fe9-42a6-b850-1891120303e0>\",\"WARC-Concurrent-To\":\"<urn:uuid:61bc1e3e-0acc-4b27-ac39-290f2de7ee4d>\",\"WARC-IP-Address\":\"52.206.101.23\",\"WARC-Target-URI\":\"https://help.component.studio/article/523-template-operators\",\"WARC-Payload-Digest\":\"sha1:6I35ITCOU6IFQFWRLKWCBZVJZHG7FLNP\",\"WARC-Block-Digest\":\"sha1:T3J524YUAP7I7RTRLCQYS6DJ2LM7E5PY\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233505362.29_warc_CC-MAIN-20230921073711-20230921103711-00559.warc.gz\"}"}