# Liquid introduction

Liquid is a template language written in Ruby.

Liquid is a template language written in Ruby. It is available as an open-source project and is used by many software projects. In VersaCommerce, Liquid is the basis of all themes: it loads dynamic content into the pages of an online shop.

## What is a template language?

A template language lets you build web pages that combine static content, which is the same on many pages, with dynamic content, which changes from page to page. The static elements that define the layout are written in HTML, the dynamic elements in Liquid. The Liquid elements act as placeholders: when the file is rendered and sent to the browser, Liquid is replaced with data from the VersaCommerce shop the theme is installed in.

## Use cases

- [Working with VersaCommerce themes](https://help.versacommerce.de/articles/14-astor-alles-ueber-themes)
- [Building a complete VersaCommerce theme](https://help.versacommerce.de/articles/theme-technik)
- [Changing an existing theme](https://help.versacommerce.de/articles/theme-technik). Merchants often ask developers to adapt a theme to their needs.

## Liquid syntax

Like other programming languages, Liquid has a syntax, works with variables and has constructs for output and logic. Liquid code is easy to tell apart from HTML by its delimiters:

- Double curly braces `{{ }}` mark output.
- Curly braces with percent signs `{% %}` mark logic and control flow.

Liquid code consists of three main parts:

- [Objects](#objects)
- [Tags](#tags)
- [Filters](#filters)

## Objects

[Liquid objects](https://developer.versacommerce.de/articles/liquid-objects) output data from the shop. In a template, objects are wrapped in double curly braces `{{ }}`:

```liquid
{{ product.title }}
```

In this example, `product` is the object and `title` is one of its properties. Every object has a list of properties. See the [product object](https://developer.versacommerce.de/articles/liquid-objects-product) for all properties of `product`.

The object `{{ product.title }}` is used in the product template of a theme. On a product page, the output is the title of the product, for example:

```text
Great T-Shirt
```

The same template is used for every product, but the objects output different data depending on the product page that is shown.

See [Liquid objects](https://developer.versacommerce.de/articles/liquid-objects) for all objects you can use in theme templates.

## Tags

[Liquid tags](https://developer.versacommerce.de/articles/liquid-tags) create logic and control flow in templates. The percent delimiters `{% %}` and the text between them produce no visible output. This lets you assign variables and create conditions or loops without showing the Liquid logic on the page.

For example, you can use tags to show different content depending on whether a product is available:

```liquid
{% if product.available %}
<h2>Price: €99.99</h2>
{% else %}
<h2 class="sold-out">Sorry, this product is sold out.</h2>
{% endif %}
```

If the product is available, the output is:

```text
Price: €99.99
```

If the product is not available, the output is:

```text
Sorry, this product is sold out.
```

The example uses the control flow tags `if` and `else`.

Liquid tags fall into these groups:

- [Control flow tags](https://developer.versacommerce.de/articles/liquid-tags-control-flow-tags)
- [Iteration tags](https://developer.versacommerce.de/articles/liquid-tags-iteration-tags)
- [Theme tags](https://developer.versacommerce.de/articles/liquid-tags-theme-tags)
- [Variable tags](https://developer.versacommerce.de/articles/liquid-tags-variable-tags)
- [Deprecated tags](https://developer.versacommerce.de/articles/liquid-tags-deprecated-tags)

## Filters

[Liquid filters](https://developer.versacommerce.de/articles/liquid-filters) change the output of numbers, strings, objects and variables. They are used inside an output tag `{{ }}` and start with a pipe character `|`.

A simple example is the string filter `capitalize`:

```liquid
{{ 'hello, world!' | capitalize }}
```

The filter capitalizes the first letter of the string. The output is:

```text
Hello, world!
```

You can chain several filters. They are applied from left to right:

```liquid
{{ 'hello, world!' | capitalize | remove: 'world' }}
```

The string is capitalized first, then the word `world` is removed. The output is:

```text
Hello, !
```

Liquid filters fall into these groups:

- [Array filters](https://developer.versacommerce.de/articles/liquid-filters-array-filters)
- [Color filters](https://developer.versacommerce.de/articles/liquid-filters-color-filters)
- [HTML filters](https://developer.versacommerce.de/articles/liquid-filters-html-filters)
- [Math filters](https://developer.versacommerce.de/articles/liquid-filters-math-filters)
- [Money filters](https://developer.versacommerce.de/articles/liquid-filters-money-filters)
- [String filters](https://developer.versacommerce.de/articles/liquid-filters-string-filters)
- [URL filters](https://developer.versacommerce.de/articles/liquid-filters-url-filters)
- [Additional filters](https://developer.versacommerce.de/articles/liquid-filters-additional-filters)
