<p>You could run a query to fetch the <code>folderId</code> you need based on the name:</p>

<pre class="lang-twig prettyprint-override"><code>{# Change this to your volumeId #}
{% set volumeId = yourVolumeId %}

{# Change this to your folderName #}
{% set folderName = yourFolderName %}

{# Returns an ID if there is a match, otherwise false #}
{% set folderId = craft
    .query()
    .select(['id'])
    .from('{{%volumefolders}}')
    .where(['=','parentId', volumeId])
    .andWhere(['=','name', folderName])
    .scalar() %}

{% if folderId %}
    {% set assets = craft.assets().folderId(folderId).all() %}

    {% for asset in assets %}
        ...
    {% endfor %}
{% endif %}
</code></pre>

CC BY-SA 4.0
2020-03-10T09:18:06.290Z
2020-03-10T09:18:06.290Z
Oli
<p>How do I reference a specific folder (by name) inside of a specific volume.  I cannot use the folder ID, I must use the folder name because the name of the folder is a variable related to specific entries.</p>

<craft3><assets>
How to reference a folder inside of a volume, Craft 3
# How to reference a folder inside of a volume, Craft 3

(Asked by: username_0 on 2020-03-09)

How do I reference a specific folder (by name) inside of a specific volume. I cannot use the folder ID, I must use the folder name because the name of the folder is a variable related to specific entries.

**Tags:** craft3, assets

---

## 1 answers

### Answer by username_1 on 2020-03-10. Score: 2

You could run a query to fetch the folderId you need based on the name:
{# Change this to your volumeId #}
{% set volumeId = yourVolumeId %}

{# Change this to your folderName #}
{% set folderName = yourFolderName %}

{# Returns an ID if there is a match, otherwise false #}
{% set folderId = craft
    .query()
    .select(['id'])
    .from('{{%volumefolders}}')
    .where(['=','parentId', volumeId])
    .andWhere(['=','name', folderName])
    .scalar() %}

{% if folderId %}
    {% set assets = craft.assets().folderId(folderId).all() %}

    {% for asset in assets %}
        ...
    {% endfor %}
{% endif %}


---

