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.
Asset URL Filters
Section titled “Asset URL Filters”asset_url filter
Section titled “asset_url ”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 }}/files/theme-key/assets/css/main.css?v=theme-key&c=1.0.0/files/theme-key/assets/js/app.js?v=theme-key&c=1.0.0/files/theme-key/assets/images/logo.svg?v=theme-key&c=1.0.0Common 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">absolute_asset_url filter
Section titled “absolute_asset_url ”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 }}/files/theme-key/assets/images/og-image.jpg?v=theme-keyImage URL Filter
Section titled “Image URL Filter”image_url filter
Section titled “image_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:
| Parameter | Type | Description |
|---|---|---|
width | number | Target width in pixels |
height | number | Target height in pixels |
fit | string | How to fit the image: cover, contain, fill, inside, outside |
gravity | string | Focus area: center, north, south, east, west, etc. |
focalX | number | Horizontal focal point (0-100) |
focalY | number | Vertical 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' }}/media/event-image.jpg?w=400&fx=50&fy=50/media/event-image.jpg?w=800&h=450&fx=50&fy=50/media/event-image.jpg?w=800&h=450&f=cover&fx=50&fy=50With 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:
| Mode | Description |
|---|---|
cover | Scales the image to fill both dimensions, cropping if necessary |
contain | Scales the image to fit within both dimensions, may letterbox |
fill | Stretches the image to fill both dimensions exactly |
inside | Like contain, but never upscales |
outside | Like cover, but never downscales |
img_url filter
Section titled “img_url ”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 }}File URL Filter
Section titled “File URL Filter”file_url filter
Section titled “file_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 %}HTML Tag Filters
Section titled “HTML Tag Filters”These filters wrap asset URLs in HTML tags for convenience.
stylesheet_tag filter
Section titled “stylesheet_tag ”Wraps a URL in a <link> tag for CSS stylesheets.
Syntax:
{{ url | stylesheet_tag }}{{ 'css/main.css' | asset_url | stylesheet_tag }}<link href="/files/theme-key/assets/css/main.css?v=theme-key" rel="stylesheet" type="text/css" media="all" />script_tag filter
Section titled “script_tag ”Wraps a filename in a <script> tag with the full asset URL.
Syntax:
{{ 'filename.js' | script_tag }}{{ 'js/main.js' | script_tag }}<script src="/files/theme-key/assets/js/main.js?v=theme-key" type="text/javascript"></script>Custom Attribute Filter
Section titled “Custom Attribute Filter”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:
| Parameter | Type | Required | Description |
|---|---|---|---|
attribute | string | Yes | The custom attribute name to query |
collection | string | Yes* | The collection to search (e.g., 'events', 'people') |
value | string/object | Yes* | The ID value to match against |
limit | number | No | Maximum number of results |
depth | number | No | Relationship depth for populated fields |
sort | string | No | Sort field and direction |
locale | string | No | Locale 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 %}{# Pass the relation object directly #}{% assign related_events = person | custom_attribute_relations: attribute: 'featured_artist', collection: 'events' %}Example Usage
Section titled “Example Usage”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 %}