Skip to content

URL Filters

URL filters generate URLs for theme assets, images, and files. These filters are essential for loading static assets and displaying optimized images in your theme.

Generates a URL for a file in your theme’s assets/ directory. The URL includes cache-busting parameters based on the theme version.

Syntax:

{{ 'path/to/file' | asset_url }}

Input: A string path relative to the assets/ directory.

Output: A fully-qualified URL to the asset with cache-busting parameters.

{{ 'css/main.css' | asset_url }}
{{ 'js/app.js' | asset_url }}
{{ 'images/logo.svg' | asset_url }}

Common usage with stylesheet and script tags:

<link rel="stylesheet" href="{{ 'css/main.css' | asset_url }}">
<script src="{{ 'js/app.js' | asset_url }}"></script>
<img src="{{ 'images/hero-bg.jpg' | asset_url }}" alt="Hero background">

Similar to asset_url, but without the cache-busting version parameter. The name is historical—in most cases both filters produce relative URLs.

Syntax:

{{ 'path/to/file' | absolute_asset_url }}
{{ 'images/og-image.jpg' | absolute_asset_url }}

Generates an optimized image URL with optional transformation parameters. This filter works with media objects from the CMS and supports automatic focal point handling.

Syntax:

{{ image | image_url }}
{{ image | image_url: width: 800 }}
{{ image | image_url: width: 800, height: 600, fit: 'cover' }}

Parameters:

ParameterTypeDescription
widthnumberTarget width in pixels
heightnumberTarget height in pixels
fitstringHow to fit the image: cover, contain, fill, inside, outside
gravitystringFocus area: center, north, south, east, west, etc.
focalXnumberHorizontal focal point (0-100)
focalYnumberVertical focal point (0-100)

Basic usage:

{# Simple resize #}
{{ event.image | image_url: width: 400 }}
{# Resize with specific dimensions #}
{{ event.image | image_url: width: 800, height: 450 }}
{# Resize with fit mode #}
{{ event.image | image_url: width: 800, height: 450, fit: 'cover' }}

With focal point override:

{# Override the default focal point #}
{{ event.image | image_url: width: 800, height: 450, focalX: 30, focalY: 20 }}

Responsive images example:

<picture>
<source
media="(min-width: 1200px)"
srcset="{{ event.image | image_url: width: 1200 }}">
<source
media="(min-width: 768px)"
srcset="{{ event.image | image_url: width: 800 }}">
<img
src="{{ event.image | image_url: width: 400 }}"
alt="{{ event.image.alt | default: event.title }}">
</picture>

Fit modes explained:

ModeDescription
coverScales the image to fill both dimensions, cropping if necessary
containScales the image to fit within both dimensions, may letterbox
fillStretches the image to fill both dimensions exactly
insideLike contain, but never upscales
outsideLike cover, but never downscales

A simpler filter that extracts the source URL from a media object. Does not support transformation parameters.

Syntax:

{{ image | img_url }}

Input: A media object or string URL.

Output: The src property if the input is an object, otherwise returns the input unchanged.

{# Works with media objects #}
{{ event.image | img_url }}
{# Also works with plain strings #}
{{ 'https://example.com/image.jpg' | img_url }}

Generates a URL for downloadable files such as PDFs, documents, or other non-image media.

Syntax:

{{ file | file_url }}

Input: A file object from the CMS or a string URL.

Output: The file’s source URL.

{% if event.program_pdf %}
<a href="{{ event.program_pdf | file_url }}" download>
Download Program (PDF)
</a>
{% endif %}

These filters wrap asset URLs in HTML tags for convenience.

Wraps a URL in a <link> tag for CSS stylesheets.

Syntax:

{{ url | stylesheet_tag }}
{{ 'css/main.css' | asset_url | stylesheet_tag }}

Wraps a filename in a <script> tag with the full asset URL.

Syntax:

{{ 'filename.js' | script_tag }}
{{ 'js/main.js' | script_tag }}

custom_attribute_relations filter

Section titled “custom_attribute_relations ”

Looks up content items that have a specific custom attribute value. This is an advanced async filter for querying related content via custom attributes.

Syntax:

{{ collection_name | custom_attribute_relations: attribute: 'attribute_name', value: related_id }}
{{ input_object | custom_attribute_relations: attribute: 'attribute_name', collection: 'collection_name' }}

Parameters:

ParameterTypeRequiredDescription
attributestringYesThe custom attribute name to query
collectionstringYes*The collection to search (e.g., 'events', 'people')
valuestring/objectYes*The ID value to match against
limitnumberNoMaximum number of results
depthnumberNoRelationship depth for populated fields
sortstringNoSort field and direction
localestringNoLocale for localized content

*Either pass the collection as the input string or via the collection parameter.

Output: An array of matching content items.

{# Find all events where custom attribute 'featured_artist' equals this person's ID #}
{% assign related_events = 'events' | custom_attribute_relations: attribute: 'featured_artist', value: person.id, limit: 6 %}
{% for event in related_events %}
<a href="/events/{{ event.slug }}">{{ event.title }}</a>
{% endfor %}

Finding events by a custom “composer” attribute:

{% assign composer_events = 'events' | custom_attribute_relations:
attribute: 'composer',
value: work.id,
limit: 10,
sort: 'startDate' %}
{% if composer_events.size > 0 %}
<h2>Upcoming Performances</h2>
{% for event in composer_events %}
<article>
<h3>{{ event.title }}</h3>
<time>{{ event.startDate | date: '%B %d, %Y' }}</time>
</article>
{% endfor %}
{% endif %}