How can i add all images in a blog post using twig syntax?

I was wondering if there is a way to add all images that belongs to that post using twig syntax in my blog_item.html.twig file. I know i could use markdown for this purpose like:

![](nature-1.jpg)

![](nature-2.jpg)

![](nature-3.jpg)

![](nature-4.jpg)

but this isn’t an option for my project. I tried to add something like that:

{% if page.media.images %}

{{page.media.images}}

{% endif %}

in my templates/partials/blog_item.html.twig but didn’t work. What i m missing here? I searched almost all the grav documentation but cant find anything.

It would be very much appreciated if someone could give me some help. Thanks in advance.

@d3s1gn3r, To list all images in the folder of a page, try the following in your Twig template:

{% for image in page.media.images %}
    {{ image.html }}
{% endfor %}
1 Like

Wow this was impressive and it works perfect. Thank you so much @anon76427325. Just one more question. Is there any way to exclude the very first image from showing it in the post page ??

@d3s1gn3r, See Twig documentation on the loop variable:

Variable Description
loop.index The current iteration of the loop. (1 indexed)
loop.index0 The current iteration of the loop. (0 indexed)
loop.revindex The number of iterations from the end of the loop (1 indexed)
loop.revindex0 The number of iterations from the end of the loop (0 indexed)
loop.first True if first iteration
loop.last True if last iteration
loop.length The number of items in the sequence
loop.parent The parent context

Try:

{% for image in page.media.images %}
    {% if not loop.first %}
        {{ image.html }}
    {% endif %}
{% endfor %}
1 Like

@anon76427325 once again your solution worked out of the box!! Thank you so much for your valuable help.