1

Trying to figure out how to get the "name" and "handle" of an asset volume, given the volume ID. Tried all the obvious things, no luck!

2

The Volumes service is available via craft.app.volumes, so you can do

{% set volume = craft.app.volumes.getVolumeByHandle('volumeHandle') %}
{{ volume.name }}

or

{% set volume = craft.app.volumes.getVolumeById(123) %}
{{ volume.name }}

Additionally, if you have an Asset model available, you can get its volume like this:

{% set volume = asset.volume %}
{{ volume.name }}
1

Figured it out:

{% set query = craft.assets.volume('volumeHandle').one() %}
{{ query.volume.name }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.