Skip to content

Instantly share code, notes, and snippets.

@renebakx
Created September 7, 2017 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save renebakx/b96ab9bc628812b899d311f231866304 to your computer and use it in GitHub Desktop.
Save renebakx/b96ab9bc628812b899d311f231866304 to your computer and use it in GitHub Desktop.
Rendering a single field with multiple items at random in Drupal 8 TWIG
{#
So you have field that can hold 5 images, but you want them to render at random in the frontend?
No problem, get https://www.drupal.org/project/tlh version 8.x-1.6 or higher and use the shuffle filter!
#}
{% for item in items|shuffle %}
{{- item.content -}}
{% endfor %}
{# Be aware of render cache when doing this trick #}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment