Skip to content Skip to footer navigation
You are reading the docs for an old version of Statamic. Consider upgrading to Statamic 6.

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.

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.