I am looking for some advice on how to best streamline a gallery system on a site, but having trouble wrapping my head around the syntax needed to eager load nested asset fields with categories inside a related entry. Any help is appreciated!
Structure:
- The "exhibition" section has an "Entries" field named galleryEntry
- That field relates to entries in the "gallery" section.
- The "gallery" section has an "Assets" field called assetGallery that can contain multiple images
- These images have a title and a "category" field called workCategory.
In the /exhibition/_entry template, I'm trying to display a gallery of images with asset thumbnail, asset title, and asset category. Simplified code:
{% if galleryEntry|length %}
{% set relatedAssets = galleryEntry.assetGallery.all() %}
<div class="gallery">
{% for work in relatedAssets %}
<figure>
<img class="thumb" src="{{ work.url }}" alt="{{ work.title }}"/>
<figcaption>
Title: {{ work.title }} /
Category: {{ work.workCategory.one().title}}
</figcaption>
</figure>
{% endfor %}
</div>
{% endif %}