Retrieve filename from readDir result

I want to serve images on a random basis. This works inside an HTML file:

{{ (readDir "content/teaser-images" | shuffle | first 1) }}

But it produces only this output:

[0xc01268add0]

How can I access the full path oder at least the filename?

Thank you for advice.

Probably via {{ $shuffledResult.Permalink }} but without a proper full sample we can’t know.

Oh, sorry - it looks like this:

<div class="breadcrumbs-image-container">
    <img class="breadcrumbs-image" src="{{ (readDir "content/teaser-images" | shuffle | first 1) }}" />
</div>

If the filename could be handed over to the src tag, that would be good - if a full path could be handed, even better!

Thank you in advance for your kind advice.

Found out myself - this works well:

{{range (readDir "content/teaser-images" | shuffle | first 1) }}{{ .Name}}{{ end }}

1 Like