Page second media

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

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

For Second image we try to get but no luck

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

Please guide me on my above question.

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.

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

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

when print it there are nothing return.

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:

{{ dump(page.media) }}

@rhukster thanks now it’s working