1

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.

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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