Created
September 7, 2017 12:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
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