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:
//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.
{{ 'shop.css' | asset_url }}
//cdn.versacommerce.de/s/files/1/0087/0462/t/394/assets/shop.css?28253
assetimgurl
Returns the asset URL of an image in the "assets" folder of a theme. asset_img_url accepts an image size parameter or a named size parameter.
{{ 'logo.png' | asset_img_url: '300x' }}
//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.
{{ 'size-chart.pdf' | file_url }}
//cdn.versacommerce.de/s/files/1/0087/0462/files/size-chart.pdf?28261
fileimgurl
Returns the asset URL of an image from the Files page of the admin. file_img_url accepts an image size parameter or a named size parameter.
{{ 'logo.png' | file_img_url: '1024x768' }}
//cdn.versacommerce.de/s/files/1/0246/0527/files/logo_1024x768.png?42
customerloginlink
Creates a link to the customer login page.
{{ 'Log in' | customer_login_link }}
<a href="/account/login" id="customer_login_link">Log in</a>
globalasseturl
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.
{{ 'prototype.js' | global_asset_url | script_tag }}
<script src="//cdn.versacommerce.de/s/global/prototype.js?1" type="text/javascript"></script>
These global assets are available:
{{ '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 }}
{{ 'prototype/1.5/prototype.js' | global_asset_url | script_tag }}
{{ 'prototype/1.6/prototype.js' | global_asset_url | script_tag }}
{{ '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 }}
{{ 'ga.js' | global_asset_url | script_tag }}
{{ 'mootools.js' | global_asset_url | script_tag }}
{{ 'lightbox.css' | global_asset_url | stylesheet_tag }}
{{ 'lightbox.js' | global_asset_url | script_tag }}
{{ 'lightbox/v1/lightbox.css' | global_asset_url | stylesheet_tag }}
{{ 'lightbox/v1/lightbox.js' | global_asset_url | script_tag }}
{{ '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 }}
{{ '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 }}
{{ 'list_collection.css' | global_asset_url | stylesheet_tag }}
{{ 'search.css' | global_asset_url | stylesheet_tag }}
{{ 'textile.css' | global_asset_url | stylesheet_tag }}
{{ '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 | image_url: width: 100, height: 100 }}
{{ variant | image_url: width: 720, height: 720 }}
{{ line_item | image_url: width: 1024 }}
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:
{{ variant.image | image_url: width: 300, height: 300 }}
{{ variant.image.src | image_url: width: 240 }}
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, 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. |
{{ 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.
{{ 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.
{{ product | image_url: width: 125 }}
{{ 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:
topcenterbottomleftright
If you pass both width and height and neither crop nor pad_color, crop defaults to center.
{{ 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.
{{ 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.
{{ product | image_url: width: 400, height: 400, pad_color: 000 }}
{{ 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:
{{ 'VersaCommerce' | link_to: 'https://www.versacommerce.de' }}
<a href="https://www.versacommerce.de">VersaCommerce</a>
You can add supported HTML attributes, separated by a comma (,), in this format:
attribute-name: "attribute-value"
For example, set the title and class attributes:
{{ 'VersaCommerce' | link_to: 'https://www.versacommerce.de', title: "A link to VersaCommerce", class: "link-class" }}
<a title="A link to VersaCommerce" class="link-class" href="https://www.versacommerce.de">VersaCommerce</a>
linktovendor
Creates an HTML link to a collection page that lists all products of a vendor.
{{ 'VersaCommerce' | link_to_vendor }}
<a href="/collections/vendors?q=VersaCommerce" title="VersaCommerce">VersaCommerce</a>
You can add supported HTML attributes in this format:
attribute-name: "attribute-value"
For example, set the class attribute:
{{ 'VersaCommerce' | link_to_vendor: class: "link-class" }}
If you include an href attribute, the generated vendor link overrides it.
linktotype
Creates an HTML link to a collection page that lists all products of a product type.
{{ "jeans" | link_to_type }}
<a href="/collections/types?q=jeans" title="jeans">jeans</a>
You can add supported HTML attributes in this format:
attribute-name: "attribute-value"
For example, set the class attribute:
{{ 'jeans' | link_to_type: class: "link-class" }}
If you include an href attribute, the generated type link overrides it.
linktotag
Creates a link to all products in a collection that have a given tag.
<!-- collection.tags = ["Mens", "Womens", "Sale"] -->
{% for tag in collection.tags %}
{{ tag | link_to_tag: tag }}
{% endfor %}
<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>
linktoadd_tag
Creates a link to all products in a collection that have a given tag plus all tags already selected.
<!-- collection.tags = ["Mens", "Womens", "Sale"] -->
{% for tag in collection.tags %}
{{ tag | link_to_add_tag: tag }}
{% endfor %}
<!-- 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>
linktoremove_tag
Creates a link to all products in a collection that have the selected tags, without the given tag.
<!-- collection.tags = ["Mens", "Womens", "Sale"] -->
{% for tag in collection.tags %}
{{ tag | link_to_remove_tag: tag }}
{% endfor %}
<!-- If you're on "/collections/frontpage/mens": -->
<a title="Remove tag Mens" href="/collections/frontpage">Mens</a>
paymenttypeimg_url
Returns the URL of the SVG image of a payment type. Use it with the shop.enabledpaymenttypes variable.
{% for type in shop.enabled_payment_types %}
<img src="{{ type | payment_type_img_url }}" />
{% endfor %}
<!-- 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">
shopifyasseturl
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>.
{{ 'option_selection.js' | versacommerce_asset_url }}
/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.
{{ collection.url | sort_by: 'best-selling' }}
/collections/widgets?sort_by=best-selling
You can append sort_by to the url_for_type or url_for_vendor filters.
urlfortype
Creates a URL to a collection page that contains products of a given product type.
{{ "T-shirt" | url_for_type }}
/collections/types?q=T-shirt
urlforvendor
Creates a URL to a collection page that contains products of a given vendor.
{{ "VersaCommerce" | url_for_vendor }}
/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 of the collection currently shown.
{{ product.url | within: collection }}
/collections/frontpage/products/alien-poster
If a product is collection-aware, its product template can access the collection object of the collection it belongs to. This lets you add collection-related content, for example related products.