TransWikia.com

How to Get Asset Volume Name

Craft CMS Asked by Roi Agneta on January 1, 2021

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 Answers

Figured it out:

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

Answered by Roi Agneta on January 1, 2021

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 }}

Answered by Mats Mikkel Rummelhoff on January 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP