Can you implement a "random" feature?

Actually in current version there is not a good way to do this.

However, i’ve just commited a method github (quality()) that let’s you do this for example:

{% set blog_image = page.media.images|first.grayscale().contrast(30).quality(90).brightnes s(-100).colorize(-35,81,122) %}

You can add this method yourself to your current version. It will be part of the next release.

Ooops, forgot the link:

https://github.com/getgrav/grav/commit/aecdbaaa27fc3ba230a36e0afa56a8196cee4fae

Thank you rhukster, Works like a charm :slight_smile:

Hey, is there any possibility to set a folder, where all images are in?

Is this related to the topic? You want a random image from that folder?

yes from a defined folder

You can have a user/pages/images folder, and randomize an image from that folder with page.find('/images').media.images|randomize|first

You can have a user/pages/images folder, and randomize an image from that folder with page.find(‘/images’).media.images|randomize|first

Thanks for this, it works very well for the blog template. But I cannot make it work with showcase item of a modular page. It chooses one random image at first when you clear the site cache but then keeps using the same image even though randomization works on the blog page. Should I change something in the syntax to make it work with showcase items?

I have also tried this syntax but it does the same thing; picks a random image just at first load.

{% set showcase_image = random(page.find('/images').media.images) %}
---

You could try to disable the caching in the page Advanced tab

The same syntax works on the blog template without disabling the caching though? I’d like to keep caching enabled.

I never tried the random function in a modular page, so i can’t help

I guess this is not possible. Oh well, I think I’ll need to upload images twice. One set for the showcase using the code in the first reply and one set for the blog page using the code I quoted before.

Hmm… Nope, I could not make this work for modular page showcase template either…

{% set showcase_image = page.media.images|randomize %}

So what I get is, random image thing works with regular pages but not modular pages.

Working for me in modular pages with the

{% set showcase_image = page.find('/images').media.images|randomize|first %}

method. The problem I’m having is only jpegs are displayed but gifs are ignored, I guess because calling

images

ignores the gif ‘animated’ filetype. I wonder if there’s a method to call for any media, not just images.

Use .all instead of .images

I have a question… to hide some of the images in the media.images how could we do it? ext. 00.jpg 01.jpg ??

Maybe loop over the array first, and remove specific images, then after that call |randomize filter,

thanxx