# URL filters

URL filters output links to assets on the VersaCommerce content delivery network (CDN).

URL filters output links to assets on the VersaCommerce content delivery network (CDN). They are also used to create links for filtering collections and blogs.

Many URL filter outputs contain a question mark (?) with a number appended to the file path of the asset. This is the version number of the file. In this URL, the version number is **28253**:

```text
//cdn.versacommerce.de/s/files/1/0087/0462/t/394/assets/shop.css?28253
```

URL filters always load the latest version of an asset.

## asset_url

Returns the URL of a file in the "assets" folder of a theme.

```liquid
{{ 'shop.css' | asset_url }}
```

```text
//cdn.versacommerce.de/s/files/1/0087/0462/t/394/assets/shop.css?28253
```

## asset_img_url

Returns the asset URL of an image in the "assets" folder of a theme. `asset_img_url` accepts an [image size parameter](https://developer.versacommerce.de/articles/liquid-filters-deprecated-filters#size-parameters) or a [named size parameter](https://developer.versacommerce.de/articles/liquid-filters-deprecated-filters#named-size-parameters).

```liquid
{{ 'logo.png' | asset_img_url: '300x' }}
```

```text
//cdn.versacommerce.de/s/files/1/0000/0001/t/1/assets/logo_300x.png?42
```

## file_url

Returns the URL of a file from the Files page of the admin.

```liquid
{{ 'size-chart.pdf' | file_url }}
```

```text
//cdn.versacommerce.de/s/files/1/0087/0462/files/size-chart.pdf?28261
```

## file_img_url

Returns the asset URL of an image from the Files page of the admin. `file_img_url` accepts an [image size parameter](https://developer.versacommerce.de/articles/liquid-filters-deprecated-filters#size-parameters) or a [named size parameter](https://developer.versacommerce.de/articles/liquid-filters-deprecated-filters#named-size-parameters).

```liquid
{{ 'logo.png' | file_img_url: '1024x768' }}
```

```text
//cdn.versacommerce.de/s/files/1/0246/0527/files/logo_1024x768.png?42
```

## customer_login_link

Creates a link to the customer login page.

```liquid
{{ 'Log in' | customer_login_link }}
```

```html
<a href="/account/login" id="customer_login_link">Log in</a>
```

## global_asset_url

Returns the URL of a global asset. Global assets are stored in a shared directory on the VersaCommerce servers. Using global assets can improve page load times.

```liquid
{{ 'prototype.js' | global_asset_url | script_tag }}
```

```html
<script src="//cdn.versacommerce.de/s/global/prototype.js?1" type="text/javascript"></script>
```

These global assets are available:

```liquid
{{ 'prototype.js' | global_asset_url | script_tag }}
{{ 'controls.js' | global_asset_url | script_tag }}
{{ 'dragdrop.js' | global_asset_url | script_tag }}
{{ 'effects.js' | global_asset_url | script_tag }}
```

```liquid
{{ 'prototype/1.5/prototype.js' | global_asset_url | script_tag }}
{{ 'prototype/1.6/prototype.js' | global_asset_url | script_tag }}
```

```liquid
{{ 'scriptaculous/1.8.2/scriptaculous.js' | global_asset_url | script_tag }}
{{ 'scriptaculous/1.8.2/builder.js' | global_asset_url | script_tag }}
{{ 'scriptaculous/1.8.2/controls.js' | global_asset_url | script_tag }}
{{ 'scriptaculous/1.8.2/dragdrop.js' | global_asset_url | script_tag }}
{{ 'scriptaculous/1.8.2/effects.js' | global_asset_url | script_tag }}
{{ 'scriptaculous/1.8.2/slider.js' | global_asset_url | script_tag }}
{{ 'scriptaculous/1.8.2/sound.js' | global_asset_url | script_tag }}
{{ 'scriptaculous/1.8.2/unittest.js' | global_asset_url | script_tag }}
```

```liquid
{{ 'ga.js' | global_asset_url | script_tag }}
```

```liquid
{{ 'mootools.js' | global_asset_url | script_tag }}
```

```liquid
{{ 'lightbox.css' | global_asset_url | stylesheet_tag }}
{{ 'lightbox.js' | global_asset_url | script_tag }}
```

```liquid
{{ 'lightbox/v1/lightbox.css' | global_asset_url | stylesheet_tag }}
{{ 'lightbox/v1/lightbox.js' | global_asset_url | script_tag }}
```

```liquid
{{ 'lightbox/v2/lightbox.css' | global_asset_url | stylesheet_tag }}
{{ 'lightbox/v2/lightbox.js' | global_asset_url | script_tag }}
{{ 'lightbox/v2/loading.gif' | global_asset_url }}
{{ 'lightbox/v2/close.gif' | global_asset_url }}
{{ 'lightbox/v2/overlay.png' | global_asset_url }}
{{ 'lightbox/v2/zoom-lg.gif' | global_asset_url }}
```

```liquid
{{ 'lightbox/v204/lightbox.css' | global_asset_url | stylesheet_tag }}
{{ 'lightbox/v204/lightbox.js' | global_asset_url | script_tag }}
{{ 'lightbox/v204/bullet.gif' | global_asset_url }}
{{ 'lightbox/v204/close.gif' | global_asset_url }}
{{ 'lightbox/v204/closelabel.gif' | global_asset_url }}
{{ 'lightbox/v204/donatebutton.gif' | global_asset_url }}
{{ 'lightbox/v204/downloadicon.gif' | global_asset_url }}
{{ 'lightbox/v204/loading.gif' | global_asset_url }}
{{ 'lightbox/v204/nextlabel.gif' | global_asset_url }}
{{ 'lightbox/v204/prevlabel.gif' | global_asset_url }}
```

```liquid
{{ 'list_collection.css' | global_asset_url | stylesheet_tag }}
{{ 'search.css' | global_asset_url | stylesheet_tag }}
{{ 'textile.css' | global_asset_url | stylesheet_tag }}
```

```liquid
{{ 'firebug/firebug.css' | global_asset_url | stylesheet_tag }}
{{ 'firebug/firebug.js' | global_asset_url | script_tag }}
{{ 'firebug/firebugx.js' | global_asset_url | script_tag }}
{{ 'firebug/firebug.html' | global_asset_url }}
{{ 'firebug/errorIcon.png' | global_asset_url }}
{{ 'firebug/infoIcon.png' | global_asset_url }}
{{ 'firebug/warningIcon.png' | global_asset_url }}
```

## image_url

Returns the URL of an image. You can use `image_url` on these objects:

- [product](https://developer.versacommerce.de/articles/liquid-objects-product)
- [variant](https://developer.versacommerce.de/articles/liquid-objects-variant)
- [line_item](https://developer.versacommerce.de/articles/liquid-objects-lineitem)
- [collection](https://developer.versacommerce.de/articles/liquid-objects-collection)
- [article](https://developer.versacommerce.de/articles/liquid-objects-article)
- [image](https://developer.versacommerce.de/articles/liquid-objects-image)

```liquid
{{ product | image_url: width: 100, height: 100 }}
{{ variant | image_url: width: 720, height: 720 }}
{{ line_item | image_url: width: 1024 }}
```

```text
https://cdn.versacommerce.de/s/files/1/1183/1048/products/boat-shoes.jpeg?v=1459175177&width=100&height=100&crop=center
https://cdn.versacommerce.de/s/files/1/1183/1048/products/boat-shoes.jpeg?v=1459175177&width=720&height=720&crop=center
https://cdn.versacommerce.de/s/files/1/1183/1048/products/boat-shoes.jpeg?v=1459175177&width=1024
```

You can also use `image_url` on the `image` or `src` attributes of an object:

```liquid
{{ variant.image | image_url: width: 300, height: 300 }}
{{ variant.image.src | image_url: width: 240 }}
```

```text
https://cdn.versacommerce.de/s/files/1/0159/3350/products/red_shirt.jpg?v=1398706734&width=300&height=300&crop=center
https://cdn.versacommerce.de/s/files/1/0159/3350/products/red_shirt.jpg?v=1398706734&width=240
```

`image_url` cannot transform icon files (`.ico`). If you pass a size or format for an icon file, `image_url` returns the original file.

For [line items](https://developer.versacommerce.de/articles/liquid-objects-lineitem), `image_url` returns the URL of the line item's variant image. If the variant has no image, `image_url` returns the URL of the product image.

`image_url` requires a `width` or `height` attribute.

## Parameters

`image_url` accepts these parameters.

| Parameter | Description |
|---|---|
| `width` | The width of the image in pixels, up to a maximum of 5760 px. |
| `height` | The height of the image in pixels, up to a maximum of 5760 px. |
| `crop` | If the entire image doesn't fit the requested dimensions, `crop` sets which part of the image is shown (`top`, `bottom`, `center`, `left`, `right`). |
| `format` | The file format of the displayed image (`jpg` or `pjpg`). |
| `pad_color` | The color used to pad the image if it is smaller than the requested dimensions. Accepts hex codes only. |

```liquid
{{ product | image_url: width: 450, height: 450, crop: 'top', format: 'pjpg', pad_color: 000  }}
```

Details on each parameter follow.

You can pass exact pixel dimensions for the width and height of an image, up to 5760 x 5760 px.

```liquid
{{ product | image_url: width: 450, height: 450 }}
```

`image_url` requires a `width` or `height` attribute. If neither is given, the image is not shown and the message `at least one of width or height must be supplied` is returned.

If only one attribute is given, the image is resized and keeps its aspect ratio.

If both attributes are given and the aspect ratio does not match the original image, the image is cropped. In that case pass `crop` or `pad_color`. Without either, `crop` defaults to `center`.

Whatever size you pass, an image is never larger than its original dimensions.

```liquid
{{ product | image_url: width: 125 }}
```

```liquid
{{ product | image_url: height: 500 }}
```

Pass a `crop` parameter to make sure the resulting image matches the requested dimensions. If the whole image does not fit, `crop` sets which part is shown. Valid options:

- `top`
- `center`
- `bottom`
- `left`
- `right`

If you pass both width and height and neither `crop` nor `pad_color`, `crop` defaults to `center`.

```liquid
{{ product | image_url: width: 400, height: 400, crop: 'bottom' }}
```

The `format` parameter sets the file format of the displayed image. Valid options are `jpg` and `pjpg`.

```liquid
{{ product | image_url: width: 400, height: 400, format: 'pjpg' }}
```

`pjpg` is a progressive JPEG. A browser loads a progressive JPEG at full size with gradually increasing quality, instead of loading it top to bottom in full quality like a regular JPEG.

VersaCommerce can convert these formats for you:

- PNG to JPG
- PNG to PJPG
- JPG to PJPG

Converting a lossy format like JPG into a lossless format like PNG is not practical, so these conversions are not available.

The `pad_color` parameter sets a color that pads the image if it is smaller than the requested dimensions. `pad_color` accepts hex color codes only.

```liquid
{{ product | image_url: width: 400, height: 400, pad_color: 000 }}
```

```liquid
{{ product | image_url: width: 400, height: 400, pad_color: eafaf3 }}
```

## link_to

Creates an HTML link.

The filter needs a parameter with the URL of the link. For example:

```liquid
{{ 'VersaCommerce' | link_to: 'https://www.versacommerce.de' }}
```

```html
<a href="https://www.versacommerce.de">VersaCommerce</a>
```

You can add supported HTML attributes, separated by a comma (`,`), in this format:

```text
attribute-name: "attribute-value"
```

For example, set the `title` and `class` attributes:

```liquid
{{ 'VersaCommerce' | link_to: 'https://www.versacommerce.de', title: "A link to VersaCommerce", class: "link-class" }}
```

```html
<a title="A link to VersaCommerce" class="link-class" href="https://www.versacommerce.de">VersaCommerce</a>
```

## link_to_vendor

Creates an HTML link to a collection page that lists all products of a vendor.

```liquid
{{ 'VersaCommerce' | link_to_vendor }}
```

```html
<a href="/collections/vendors?q=VersaCommerce" title="VersaCommerce">VersaCommerce</a>
```

You can add supported HTML attributes in this format:

```text
attribute-name: "attribute-value"
```

For example, set the `class` attribute:

```liquid
{{ 'VersaCommerce' | link_to_vendor: class: "link-class" }}
```

If you include an `href` attribute, the generated vendor link overrides it.

## link_to_type

Creates an HTML link to a collection page that lists all products of a product type.

```liquid
{{ "jeans" | link_to_type }}
```

```html
<a href="/collections/types?q=jeans" title="jeans">jeans</a>
```

You can add supported HTML attributes in this format:

```text
attribute-name: "attribute-value"
```

For example, set the `class` attribute:

```liquid
{{ 'jeans' | link_to_type: class: "link-class" }}
```

If you include an `href` attribute, the generated type link overrides it.

## link_to_tag

Creates a link to all products in a collection that have a given tag.

```liquid
<!-- collection.tags = ["Mens", "Womens", "Sale"] -->
{% for tag in collection.tags %}
  {{ tag | link_to_tag: tag }}
{% endfor %}
```

```html
<a title="Show products matching tag Mens" href="/collections/frontpage/mens">Mens</a>
<a title="Show products matching tag Womens" href="/collections/frontpage/womens">Womens</a>
<a title="Show products matching tag Sale" href="/collections/frontpage/sale">Sale</a>
```

## link_to_add_tag

Creates a link to all products in a collection that have a given tag plus all tags already selected.

```liquid
<!-- collection.tags = ["Mens", "Womens", "Sale"] -->
{% for tag in collection.tags %}
  {{ tag | link_to_add_tag: tag }}
{% endfor %}
```

```html
<!-- If you're on "/collections/frontpage/mens": -->
<a title="Show products matching tag Mens" href="/collections/frontpage/mens">Mens</a>
<a title="Show products matching tag Womens" href="/collections/frontpage/womens+mens">Womens</a>
<a title="Show products matching tag Sale" href="/collections/frontpage/sale+mens">Sale</a>
```

## link_to_remove_tag

Creates a link to all products in a collection that have the selected tags, without the given tag.

```liquid
<!-- collection.tags = ["Mens", "Womens", "Sale"] -->
{% for tag in collection.tags %}
  {{ tag | link_to_remove_tag: tag }}
{% endfor %}
```

```html
<!-- If you're on "/collections/frontpage/mens": -->
<a title="Remove tag Mens" href="/collections/frontpage">Mens</a>
```

## payment_type_img_url

Returns the URL of the SVG image of a payment type. Use it with the [shop.enabled_payment_types](https://developer.versacommerce.de/articles/liquid-objects-shop) variable.

```liquid
{% for type in shop.enabled_payment_types %}
  <img src="{{ type | payment_type_img_url }}" />
{% endfor %}
```

```html
<!-- If shop accepts American Express, Mastercard and Visa -->
<img src="//cdn.versacommerce.de/s/global/payment_types/creditcards_american_express.svg?3cdcd185ab8e442b12edc11c2cd13655f56b0bb1">
<img src="//cdn.versacommerce.de/s/global/payment_types/creditcards_Meister.svg?3cdcd185ab8e442b12edc11c2cd13655f56b0bb1">
<img src="//cdn.versacommerce.de/s/global/payment_types/creditcards_visa.svg?3cdcd185ab8e442b12edc11c2cd13655f56b0bb1">
```

## shopify_asset_url

Returns the URL of a global file provided by VersaCommerce (for example `option_selection.js` or `api.jquery.js`). In VersaCommerce, `shopify_asset_url` is an alias of `versacommerce_asset_url`; both return the path `/static_assets/alien/<file name>`.

```liquid
{{ 'option_selection.js' | versacommerce_asset_url }}
```

```text
/static_assets/alien/option_selection.js
```

In shops without the compatibility mode, `api.jquery.js` and `option_selection.js` are served in their older variants with the prefix `legacy-`.

## sort_by

Creates a URL to a collection page with the given `sort_by` parameter. Apply the filter to a collection URL.

```liquid
{{ collection.url | sort_by: 'best-selling' }}
```

```html
/collections/widgets?sort_by=best-selling
```

You can append `sort_by` to the `url_for_type` or `url_for_vendor` filters.

## url_for_type

Creates a URL to a collection page that contains products of a given product type.

```liquid
{{ "T-shirt" | url_for_type }}
```

```text
/collections/types?q=T-shirt
```

## url_for_vendor

Creates a URL to a collection page that contains products of a given vendor.

```liquid
{{ "VersaCommerce" | url_for_vendor }}
```

```text
/collections/vendors?q=VersaCommerce
```

## within

Creates a *collection-aware* product URL by prepending `/collections/collection-handle` to a product URL, where `collection-handle` is the [handle](https://developer.versacommerce.de/articles/liquid-basics-handle) of the collection currently shown.

```liquid
{{ product.url | within: collection }}
```

```html
/collections/frontpage/products/alien-poster
```

If a product is collection-aware, its product template can access the [collection object](https://developer.versacommerce.de/articles/liquid-objects-collection) of the collection it belongs to. This lets you add collection-related content, for example related products.
