Skip to content Skip to footer navigation

Assets Tag

Used to retrieve Assets directly from a container where you can then loop, filter, and sort them in expected but exciting ways.

Overview#

If you ever find yourself needing to loop over all the assets in a container or folder instead of selecting them manually with the assets fieldtype, this tag was designed to make you smile.

{{ assets container="photoshoots" }}
<img src="{{ url }}" alt="{{ alt }}" />
{{ /assets }}
{{-- Using Antlers Blade Components --}}
<statamic:assets
container="photoshoots"
>
<img src="{{ $url }}" alt="{{ $alt }}" />
</statamic:assets>
{{-- Using Fluent Tags --}}
@php
$assets = Statamic::tag('assets')->container('photoshoots')->fetch();
@endphp
@foreach ($assets as $asset)
<img src="{{ $asset->url }}" alt="{{ $asset->alt }}" />
@endforeach

This tag returns an array of Asset objects. You'll have access to all the data and meta data on each file.

Filtering#

Conditions#

You can filter assets using the same conditions syntax available on the Collection tag. This works against both built-in asset properties (filename, extension, size, etc.) and any custom fields defined on the container's blueprint.

{{ assets container="photos" extension:is="jpg" alt:contains="sunset" }}
<img src="{{ url }}" alt="{{ alt }}" />
{{ /assets }}
<statamic:assets
container="photos"
extension:is="jpg"
alt:contains="sunset"
>
<img src="{{ $url }}" alt="{{ $alt }}" />
</statamic:assets>

Common conditions include :is, :isnt, :contains, :starts_with, and :ends_with. See the full list on the conditions page.

Filter by Type#

Limit results to a single media type using the type parameter. Valid values are audio, image, svg, and video.

{{ assets container="uploads" type="image" }}
<img src="{{ url }}" alt="{{ alt }}" />
{{ /assets }}

Custom Query Scopes#

For more complex filtering, create a query scope and reference it with query_scope:

{{ assets container="photos" query_scope="recent_hero_shots" }}
<img src="{{ url }}" alt="{{ alt }}" />
{{ /assets }}

Parameters

id|container|handle

string

Every asset container has a unique handle. Pass it in and win! Default: assets.

folder

string

Filter the resulting assets by specific folder. Default: none.

recursive

boolean

If you enable recursion, the tag will return all the assets in all the subdirectories that match your parameters. Default: false.

not_in

string

Filter by excluding from a subdirectory or subdirectories. You may use regex, and will be matched against the file path without a leading slash. For example: not_in="img/(brand|logos)"

limit

integer

Limit the total results to a specific number.

offset

integer

Skip a specific number of results. Useful for if you want to pull the first one out as a hero image or something similar.

sort

string

Sort entries by any available asset variable, or random. Pipe-separate multiple fields for sub-sorting and specify sort direction of each field using a colon. Example: sort="size" or sort="size:asc|title:desc" to sort by size then by title.

type

string

Filter by asset type. One of audio, image, svg, or video. Default: none.

query_scope

string

Apply a custom query scope. Reference it by its handle (usually the class name in snake case).