Skip to content

Twig Media Reference

The media adapter provides URL generation for images (with ImageWorks transformations), gallery images, file downloads, and streaming. For rendering images as HTML, see cms.render.

Get the ImageWorks API URL for an image. Use this when you need just the URL (not a full <img> tag).

{# Basic image URL #}
<img src="{{ cms.media.imagePath('hero') }}" alt="Hero">
{# With ImageWorks transformations #}
<img src="{{ cms.media.imagePath('hero', {w: 800, h: 600, fit: 'crop'}) }}">
{# WebP format #}
<div style="background-image: url('{{ cms.media.imagePath('bg', {w: 1920, fm: 'webp'}) }}')"></div>
{# Custom collection and property #}
{{ cms.media.imagePath('widget', {w: 400}, {collection: 'products', property: 'photo'}) }}
{# Pass object directly (avoids re-fetching) #}
{{ cms.media.imagePath(product, {w: 600}, {collection: 'products', property: 'image'}) }}
ParameterTypeDefaultDescription
idOrObjectstring|array|nullrequiredObject ID or full object data
imageworksarray[]ImageWorks transformation parameters
optionsarray[]Options: collection, property

For available ImageWorks parameters, see the ImageWorks Reference.

Get the ImageWorks API URL for a specific gallery image.

{# By filename #}
<img src="{{ cms.media.galleryPath('vacation', 'sunset.jpg', {w: 800}) }}">
{# Dynamic selectors #}
<img src="{{ cms.media.galleryPath('vacation', 'first', {w: 400}) }}">
<img src="{{ cms.media.galleryPath('vacation', 'featured', {w: 400}) }}">
{# Custom collection #}
{{ cms.media.galleryPath('widget', 'front.jpg', {w: 300}, {collection: 'products'}) }}
ParameterTypeDefaultDescription
idOrObjectstring|array|nullrequiredObject ID or full object data
namestring|int|nullrequiredFilename, index, or dynamic selector (first, last, random, featured)
imageworksarray[]ImageWorks transformation parameters
optionsarray[]Options: collection, property

Get the complete image data object for a specific gallery image. Returns null if not found.

{% set imgData = cms.media.galleryImageData('vacation', 'sunset.jpg') %}
{% if imgData %}
<p>{{ imgData.alt }}</p>
<p>{{ imgData.width }}x{{ imgData.height }}</p>
{% endif %}
ParameterTypeDefaultDescription
idOrObjectstring|arrayrequiredObject ID or full object data
namestring|intrequiredFilename or index
optionsarray[]Options: collection, property

Downloads use Content-Disposition: attachment to force the browser download dialog.

Get the download URL for a file property.

<a href="{{ cms.media.download('report') }}">Download Report</a>
{# Custom collection and property #}
<a href="{{ cms.media.download('doc', {collection: 'documents', property: 'pdf'}) }}">Download PDF</a>
{# Password-protected #}
<a href="{{ cms.media.download('doc', {pwd: 'secret123'}) }}">Download</a>
ParameterTypeDefaultDescription
idOrObjectstring|arrayrequiredObject ID or full object data
optionsarray[]Options: collection, property, pwd

Get the download URL for a specific file in a depot.

{% set files = cms.media.depot('documents') %}
{% for file in files %}
<a href="{{ cms.media.depotDownload('documents', file.name) }}">{{ file.name }}</a>
{% endfor %}
{# File in a subfolder #}
{{ cms.media.depotDownload('docs', 'report.pdf', {path: 'reports/2024'}) }}
{{ cms.media.depotDownload('docs', 'reports/2024/report.pdf') }}
{# Password-protected #}
{{ cms.media.depotDownload('docs', 'secret.zip', {pwd: 'pass123'}) }}
ParameterTypeDefaultDescription
idOrObjectstring|arrayrequiredObject ID or full object data
namestringrequiredFilename
optionsarray[]Options: collection, property, path, pwd

Streaming uses Content-Disposition: inline and supports HTTP range requests, making it ideal for video and audio playback.

Get the stream URL for a file property.

<video controls>
<source src="{{ cms.media.stream('intro-video') }}" type="video/mp4">
</video>
<audio controls>
<source src="{{ cms.media.stream('podcast') }}" type="audio/mpeg">
</audio>
{# Custom collection #}
{{ cms.media.stream('clip', {collection: 'videos', property: 'video'}) }}
{# Password-protected #}
{{ cms.media.stream('clip', {pwd: 'secret123'}) }}
ParameterTypeDefaultDescription
idOrObjectstring|arrayrequiredObject ID or full object data
optionsarray[]Options: collection, property, pwd

Get the stream URL for a specific file in a depot.

<video controls>
<source src="{{ cms.media.depotStream('media', 'intro.mp4') }}" type="video/mp4">
</video>
{# File in a subfolder #}
{{ cms.media.depotStream('media', 'movie.mp4', {path: 'videos'}) }}
{{ cms.media.depotStream('media', 'videos/movie.mp4') }}
{# Password-protected #}
{{ cms.media.depotStream('media', 'audio.mp3', {pwd: 'pass123'}) }}
ParameterTypeDefaultDescription
idOrObjectstring|arrayrequiredObject ID or full object data
namestringrequiredFilename
optionsarray[]Options: collection, property, path, pwd

Get the list of files in a depot property.

{% set files = cms.media.depot('documents') %}
{% for file in files %}
<p>{{ file.name }} ({{ file.size }} bytes)</p>
{% endfor %}
ParameterTypeDefaultDescription
idstringrequiredObject identifier
optionsarray[]Options: collection, property
StreamDownload
Content-Dispositioninlineattachment
Range requestsYesNo
Best forVideo, audio, PDFs in-browserFiles to save locally
Password supportYesYes