I'm trying to determine if I can update this:
{% cache %}
[
{% set tags = craft.tags.group('color','season','style','venue').limit(null) %}
{% for image in craft.assets.relatedTo(tags).order('elements.dateCreated desc') %}
{% set thumbParams = {
width: 300,
height:300,
mode: 'crop'
} %}
{% set smallParams = {
width: 768,
mode: 'fit'
} %}
{
"url": "{{ image.url }}",
"filename": "{{ image.filename }}",
"imageTitle": "{{ image.imageTitle }}",
"imageThumb": "{{ image.getUrl(thumbParams) }}",
"tagsColor": [
{% for tag in image.tagsColor %}
{
"slug": "{{ tag | slugify }}",
"tag": "{{ tag }}"
}{% if not (loop.last) %},{% endif %}
{% endfor %}
],
"tagsSeason": [
{% for tag in image.tagsSeason %}
{
"slug": "{{ tag | slugify }}",
"tag": "{{ tag }}"
}{% if not (loop.last) %},{% endif %}
{% endfor %}
],
"tagsStyle": [
{% for tag in image.tagsStyle %}
{
"slug": "{{ tag | slugify }}",
"tag": "{{ tag }}"
}{% if not (loop.last) %},{% endif %}
{% endfor %}
],
"tagsVenue": [
{% for tag in image.tagsVenue %}
{
"slug": "{{ tag | slugify }}",
"tag": "{{ tag }}"
}{% if not (loop.last) %},{% endif %}
{% endfor %}
]
}{% if not loop.last %},
{% endif %}
{% endfor %}
]
{% endcache %}
To randomize the order of images. Is that possible with .order
and is that possible within cached template code? (As random would be "new" every instance.)
Note that I have the image crops and tag lookups inside the cached code, as those are intensive. The first answer, to shuffle the images after fetching them within the cached code, won't work, because the for
loop on the image set is what needs to be cached.
set
tags like this:{% set images %}{% endset %}
? Didn't know you can define arrays doing so.. – carlcs Oct 27 '14 at 16:36