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

Page second media

Started by Muut Archive 10 years ago · 4 replies · 564 views
10 years ago

How can i get second image of page media i have used code like this but not getting second image
For the last image

TWIG
{% set first_image = page.media.images|last %}

For Second image we try to get but no luck

TWIG
{% set first_image = page.media.images|slice(1, 1) %}

Please guide me on my above question.

10 years ago

Are you sure you have 2 images? slice(1, 1), should work. as the first 1 is the 2nd item (0-based offset) and the second 1 is the length of the slice. But there is an easier way.

Alternatively you can just do pages.media.images[1] and that should get the second image from they array.

10 years ago

Slice don't work here i am trying to get But it's not working Also

TWIG
{% set first_image = pages.media.images[1] %}

when print it there are nothing return.

10 years ago

Oh it should be page.media.images[1] not pages.

You can always debug by enabling the debugger in Grav and dumping the variable to the messages panel:

TWIG
{{ dump(page.media) }}

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1362 9 years ago
Archive · by Muut Archive, 9 years ago
2 939 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2959 9 years ago
Archive · by Muut Archive, 9 years ago
3 1123 9 years ago