I have a gallery in my site's <footer>
with images that are defined in a matrix field on each of my categories. If I'm viewing a category page or an entry with related categories I want to display this image gallery in the footer.
What I currently have is this:
{% if category is defined %}
{% if category.actionBilder.exists() %}
<div id="footerslide">
{% for block in category.actionBilder.limit(3).orderBy('RAND()').all() %}
{% if block.type == "actionImg" %}
<div data-image="{{block.image.one().url}}"></div>
{% endif %}
{% endfor %}
</div>
{% endif %}
{% endif %}
{% if entry is defined %}
{% set categories = craft.categories.relatedTo(entry) %}
{% for category in categories %}
{% if category.actionBilder.exists() %}
<div id="footerslide">
{% for block in category.actionBilder.limit(3).orderBy('RAND()').all() %}
{% if block.type == "actionImg" %}
<div data-image="{{block.image.one().url}}"></div>
{% endif %}
{% endfor %}
</div>
{% endif %}
{% endfor %}
{% endif %}
While it's working fine, I don't think that this is the best solution.
How would you change my code to make it better?