Files
liquid/_basics/introduction.md
2021-04-22 17:19:13 -04:00

2.2 KiB

title, description, redirect_from
title description redirect_from
Introduction An overview of objects, tags, and filters in the Liquid template language. /basics/

Liquid code can be categorized into objects, tags, and filters.

Objects

Objects tell Liquid where to show content on a page. Objects and variable names are denoted by double curly braces: {% raw %}{{{% endraw %} and {% raw %}}}{% endraw %}.

Input

```liquid {% raw %} {{ page.title }} {% endraw %} ```

Output

```text {{ page.title }} ```

In this case, Liquid is rendering the content of the title property of the page object, which contains the text {{ page.title }}.

Tags

Tags create the logic and control flow for templates. They are denoted by curly braces and percent signs: {% raw %}{%{% endraw %} and {% raw %}%}{% endraw %}.

The markup used in tags does not produce any visible text. This means that you can assign variables and create conditions and loops without showing any of the Liquid logic on the page.

Input

```liquid {% raw %} {% if user %} Hello {{ user.name }}! {% endif %} {% endraw %} ```

Output

```text Hello Adam! ```

Tags can be categorized into three types:

  • [Control flow]({{ "/tags/control-flow/" | prepend: site.baseurl }})
  • [Iteration]({{ "/tags/iteration/" | prepend: site.baseurl }})
  • [Variable assignments]({{ "/tags/variable/" | prepend: site.baseurl }})

You can read more about each type of tag in their respective sections.

Filters

Filters change the output of a Liquid object. They are used within an output and are separated by a |.

Input

```liquid {% raw %} {{ "/my/fancy/url" | append: ".html" }} {% endraw %} ```

Output

```text {{ "/my/fancy/url" | append: ".html" }} ```

Multiple filters can be used on one output. They are applied from left to right.

Input

```liquid {% raw %} {{ "adam!" | capitalize | prepend: "Hello " }} {% endraw %} ```

Output

```text {{ "adam!" | capitalize | prepend: "Hello " }} ```