Resolve Modifier
Resolves a query builder and returns either a specific item by key/index or the full array of results. Also works on arrays and collections.
Handy for grabbing a single item out of a relationship field (like the first asset from an asset field) without having to loop.
gallery:
- hero.jpg
- action-shot.jpg
- outtake.jpg
<img src="{{ gallery | resolve(0):url }}" />
<img src="{{ Statamic::modify($gallery)->resolve(0)->fetch()['url'] }}" />
<img src="/assets/hero.jpg" />
Without a key#
Omit the key to resolve the query builder into an array of all items. Useful when you want to pass the resolved data into another modifier.
{{ gallery | resolve | count }}
{{ Statamic::modify($gallery)->resolve()->count() }}
3