Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

Random and filtered hero image

Started by Jean PUJOL 6 years ago · 0 replies · 795 views
6 years ago

Hi to the Grav community,

I started with Grav by creating an inerited theme of Qwark.
I put the media files in user/pages/images with {% set my_image = page.find('/images').media['my-image.jpg'] %} .

After that I wanted my hero image to come from the pages/images folder, so I did this :

@pamtbaau:
If you want the template to find an image in the pages/images folder, do the following:

  • In the page’s frontmatter do:

    hero_image: small-bandpic.png
    Note: No path prepended

  • In the template item.html.twig file:

    {% set hero_image = page.find(’/images’).media[hero_image_name] %}

Each page of the site is only composed by images.
My final objective is to create a modular page made of hero images from the pages of my website, each hero will take a random picture of the page.

My problem is : how to make each hero image random and filtered differently ? (for example only images including the letter L). I know a randomize function exists but I don't kow how to apply it with different filters on each hero.

Sorry for my bad english, and also i don't know anything to code...
Best regards.

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 196 2 months ago
Themes & Styling · by Ian, 2 months ago
3 92 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 452 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 46 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 126 3 months ago