# Theme tags

Theme tags have many functions, including:

Theme tags have many functions, including:

- outputting template-specific HTML markup
- telling the theme which layout and snippets to use
- splitting a returned array into several pages

## comment

Lets you leave unrendered code in a Liquid template. Text between the opening and closing `comment` blocks is not output, and Liquid code inside is not executed.

```liquid
My name is Jane Doe{% comment %}, esquire{% endcomment %}.
```

```text
My name is Jane Doe.
```

## echo

Outputs an expression in the rendered HTML. This is the same as wrapping an expression in `{{` and `}}`, but it works inside [`liquid`](#liquid) tags and supports [filters](https://developer.versacommerce.de/articles/liquid-filters-introduction).

```liquid
{% liquid
if product.featured_image
  echo product.featured_image | image_url: width: 500 | image_tag: srcset: nil, width: 500
else
  echo 'product-1' | placeholder_svg_tag
endif %}
```

```html
<img src="//example-shop.versacommerce.de/products/red-shirt.jpg?v=1398706734" alt="Red Shirt Small" width="500">
```

## form

Creates an HTML `<form>` element with the `<input>` elements needed to submit the form to a given endpoint.

## form types and tag parameters

VersaCommerce themes can create and submit many kinds of forms. Adding a product to the cart, registering a customer account and commenting on a blog article all need `<form>` elements with different attributes and `<input>` elements.

The `{% form %}` tag needs a type and can take extra parameters. For example, the form to comment on a blog article has the type `new_comment` and needs an [article](https://developer.versacommerce.de/articles/liquid-objects-article) object as a parameter.

```liquid
{% form 'new_comment', article %}
...
{% endform %}
```

The form types and their parameters are listed below. A form name that VersaCommerce does not know renders a plain `<form>` sent with GET. There is no `currency` or `localization` form type.

### activate_customer_password

Creates a form to activate a customer account on the account activation template. The activation data (for example the token) has to be provided by the page.

```liquid
{% form 'activate_customer_password' %}
...
{% endform %}
```

```html
<form method="post" action="/account/activate" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="activate_customer_password">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

### cart

Creates a form around the cart. It is sent with GET to the cart page.

```liquid
{% form 'cart', cart %}
...
{% endform %}
```

```html
<form method="get" action="/cart" id="cart_form" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="cart">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

### contact

Creates a form to send an email through the storefront contact form. Depending on the configured spam protection, a captcha token field is added.

```liquid
{% form 'contact' %}
...
{% endform %}
```

```html
<form method="post" action="/contact#contact_form" class="contact-form" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="contact">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

### create_customer

Creates a form to register a new customer account on the registration template.

```liquid
{% form 'create_customer' %}
...
{% endform %}
```

```html
<form method="post" action="/account/create" id="create_customer" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="create_customer">
  <input type="hidden" name="utf8" value="✓">
  <input type="hidden" name="skip_billing_address" value="true">
  ...
</form>
```

### customer

Creates a form to collect customer details without registering an account, for example for a newsletter sign-up. Depending on the configured spam protection, a captcha token field is added. To register a customer account, use the `create_customer` form.

```liquid
{% form 'customer' %}
...
{% endform %}
```

```html
<form method="post" action="/customer#contact_form" id="contact_form" class="contact-form" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="contact">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

### customer_address

Creates a form to create or edit a customer address on the addresses template. Pass `customer.new_address` for a new address, or an existing `address` to edit it and prefill the fields. The form is sent with GET to the current URL unless you set an `action` attribute.

```liquid
{% form 'customer_address', customer.new_address %}
...
{% endform %}
```

```html
<form method="get" id="address_form_new" accept-charset="UTF-8">
  ...
</form>
```

### customer_login

Creates a login form for customer accounts on the login template.

```liquid
{% form 'customer_login' %}
...
{% endform %}
```

```html
<form method="post" action="/account/authenticate" id="customer_login" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="customer_login">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

### guest_login

Creates a form on the login template that continues as a guest instead of logging in to an account.

```liquid
{% form 'guest_login' %}
...
{% endform %}
```

```html
<form method="post" action="/account/login" id="customer_login_guest" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="guest_login">
  <input type="hidden" name="utf8" value="✓">
  <input type="hidden" name="guest" value="true">
  ...
</form>
```

### new_comment

Creates a form to post a comment on the article template. Requires the `article` object as a parameter.

```liquid
{% form 'new_comment', article %}
...
{% endform %}
```

```html
<form method="post" action="/blogs/news/my-article/comments#comment_form" id="comment_form" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="new_comment">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

### product

Creates a form to add a product variant to the cart. Requires a `product` object as a parameter.

```liquid
{% form 'product', product %}
...
{% endform %}
```

```html
<form method="post" action="/cart/add" id="product_form_123456789" enctype="multipart/form-data" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="product">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

### recover_customer_password

Creates a form on the login template to request a password reset email.

```liquid
{% form 'recover_customer_password' %}
...
{% endform %}
```

```html
<form method="post" action="/account/recover" id="recover_customer_password_form" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="recover_customer_password">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

### reservation

Creates a form to reserve a product, for shops with reservations enabled.

```liquid
{% form 'reservation' %}
...
{% endform %}
```

```html
<form method="post" action="/reservations" id="reservation_form" accept-charset="UTF-8">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

### reset_customer_password

Creates a form on the password reset template that lets a customer set a new password. The reset data (for example the token) has to be provided by the page.

```liquid
{% form 'reset_customer_password' %}
...
{% endform %}
```

```html
<form method="post" action="/account/reset" id="create_customer" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="reset_customer_password">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

### restriction_password

Creates a form to enter the password of a restricted area of the shop.

```liquid
{% form 'restriction_password' %}
...
{% endform %}
```

```html
<form method="post" action="/restriction_password" id="login_form" class="restriction-password-form" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="restriction_password">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

### revocation

Creates a form that lets customers send a revocation (withdrawal) request. Depending on the configured spam protection, a captcha token field is added.

```liquid
{% form 'revocation' %}
...
{% endform %}
```

```html
<form method="post" action="/services/revocation" id="revocation-form" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="revocation">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

### storefront_password

Creates a form on the password template to enter a password-protected storefront.

```liquid
{% form 'storefront_password' %}
...
{% endform %}
```

```html
<form method="post" action="/password" id="login_form" class="storefront-password-form" accept-charset="UTF-8">
  <input type="hidden" name="form_type" value="storefront_password">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

## Modifying form attributes

When you create a `<form>` element, you can change its default attributes or add new ones. Add the attribute as a named parameter to the form tag and give it a value.

```liquid
{% form 'product', product, id: 'newID', class: 'custom-class', data-example: '100' %}
  ...
{% endform %}
```

```html
<form method="post" action="/cart/add" id="newID" class="custom-class" data-example="100" enctype="multipart/form-data">
  <input type="hidden" name="form_type" value="product">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

You can also use [Liquid variables](https://developer.versacommerce.de/articles/liquid-tags-variable-tags) as parameters:

```liquid
{% capture form_id %}addToCartForm-{{ section.id }}{% endcapture %}
{% form 'product', product, id: form_id %}
...
{% endform %}
```

```html
<form method="post" action="/cart/add" id="addToCartForm-36197306239" enctype="multipart/form-data">
  <input type="hidden" name="form_type" value="product">
  <input type="hidden" name="utf8" value="✓">
  ...
</form>
```

## Redirecting customers with the return_to form tag parameter

By default, each form type sends customers to a given page. For example, the `product` form type redirects to the cart page.

Use the `return_to` parameter to redirect to a page you choose:

- `'back'` returns to the page the customer was on before submitting the form.
- A relative path, for example `'/collections/all'`.
- A [routes attribute](https://developer.versacommerce.de/articles/liquid-objects-routes), for example `routes.all_products_collection_url`.

The tag adds the value as an escaped hidden `return_to` field. The receiving endpoint decides how the redirect is handled, for example when adding to the cart or logging in.

```liquid
{% form 'product', product, return_to: routes.all_products_collection_url %}
  <input type="hidden" name="id" value="{{ product.selected_or_first_available_variant.id }}">
  <button type="submit">Add to cart</button>
{% endform %}
```

## layout

Add `{% layout 'alternate' %}` at the top of a template file to use another layout file from your theme's **layout** folder. Without an alternate layout, the template uses **theme.liquid**:

```liquid
{% layout 'full-width' %}
```

If a template should **not** use a layout file, set the layout to `none`:

```liquid
{% layout none %}
```

## liquid

Lets you write several tags inside one set of delimiters.

```liquid
{% liquid
case section.blocks.size
when 1
  assign column_size = ''
when 2
  assign column_size = 'one-half'
when 3
  assign column_size = 'one-third'
else
  assign column_size = 'one-quarter'
endcase %}
```

Use the [echo](#echo) tag to output an expression inside a `{% liquid %}` tag.

## paginate

Splitting products, blog articles and search results across several pages is a necessary part of theme design, because a [for loop](https://developer.versacommerce.de/articles/liquid-tags-iteration-tags#for) is limited to 50 results per page.

The `paginate` tag works with the `for` tag to split content across pages. It must wrap a `for` block that loops over an array, as in this example:

```liquid
{% paginate collection.products by 5 %}
  {% for product in collection.products %}
    <!-- show product details here -->
  {% endfor %}
{% endpaginate %}
```

The `by` parameter is followed by an integer between **1** and **50** that tells the `paginate` tag how many results to output per page.

Inside the `paginate` tags you can access the attributes of the [paginate object](https://developer.versacommerce.de/articles/liquid-objects-paginate), including the attributes that output the links needed to navigate the generated pages.

## raw

Outputs Liquid code on a page without parsing it.

```liquid
{% raw %}{{ 5 | plus: 6 }}{% endraw %} equals 11.
```

```text
{{ 5 | plus: 6 }} equals 11.
```

## render

Renders a snippet from the theme's **snippets** folder.

```liquid
{% render 'snippet-name' %}
```

You do not need to write the `.liquid` extension of the file name.

When a snippet is rendered, its code does **not** automatically have access to variables assigned with [variable tags](https://developer.versacommerce.de/articles/liquid-tags-variable-tags) in the snippet's parent template. Variables assigned inside the snippet are not available outside it either. This encapsulation improves performance and makes theme code easier to understand and maintain.

Inside a snippet rendered with `render`, the deprecated `include` tag cannot be used.

## Passing variables to a snippet

Variables assigned with [variable tags](https://developer.versacommerce.de/articles/liquid-tags-variable-tags) can be passed to a snippet as parameters of the `render` tag:

```liquid
{% assign my_variable = 'apples' %}
{% render 'name', my_variable: my_variable, my_other_variable: 'oranges' %}
```

Global objects do not need to be passed. They are available in every file.

Assigning a variable inside the snippet that is also assigned in the parent template does not overwrite its value in the parent template.

## The with parameter

Use the `with` and `as` parameters to pass a single object to a snippet:

```liquid
{% assign featured_product = all_products['product_handle'] %}
{% render 'product' with featured_product as product %}
```

In this example, the `product` variable in the snippet holds the value of `featured_product` from the parent template.

## The for parameter

Use the `for` and `as` parameters to render a snippet once for each value of an enumerable object:

```liquid
{% assign variants = product.variants %}
{% render 'variant' for variants as variant %}
```

In this example, the snippet is rendered once for each product variant, and the `variant` variable holds a variant object inside the snippet.

With the `for` parameter, the [forloop object](https://developer.versacommerce.de/articles/liquid-objects-for-loops) is available inside the snippet.

## section

Renders a section from the theme's **sections** folder.

```liquid
{% section 'header' %}
```

```html
<div id="shopify-section-header" class="shopify-section">
  <!-- content of sections/header.liquid -->
</div>
```

Sections included with the `{% section %}` tag are rendered as "static" sections. The wrapper keeps the `shopify-section` ID and class for compatibility with existing themes. See [Theme structure](https://developer.versacommerce.de/articles/theme-structure) for JSON templates and section groups.

Each section supports section-specific tags to define settings, styles and scripts. See [Section and block tags](https://developer.versacommerce.de/articles/liquid-tags-section-and-block-tags).

## style

The `{% style %}` tag renders an HTML `<style>` tag with a VersaCommerce data attribute. Color settings inside a `{% style %}` tag can be updated live from the theme editor without a full page reload.

```liquid
{% style %}
  .hero__background-color-container {
    background-color: {{ section.settings.background_color }};
  }
{% endstyle %}
```
