Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.
If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.
{{ with index .Pages 0 }}
{{ with .Resources.ByType "image" }}
{{ with index . 0 }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
{{ end }}
@jmooring
Thank you so much, it’s amazing.
Jut one question, for my knowledges and understanding about Hugo.
How can i specify With and Height parameters in this case ? In front matter ? or declare as variables before the loop ?
If you want to change the size of the image, use one of the image processing methods. For example:
{{ with index .Pages 0 }}
{{ with .Resources.ByType "image" }}
{{ with index . 0 }}
{{ with .Fill "300x200" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
{{ end }}
{{ end }}
In this example the target dimensions are hardcoded in the template. If you don’t want to hardcode the target dimensions, you could specify them in front matter..
@jmooring Thank you very much for all these explanations. It becomes clearer.
I try now to get the image by the name and follow the methods
Like this
{{ with index .Pages 0 }}
{{ with .Resources.Match "images/cover.*" }}
{{ with index . 0 }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
{{ end }}
And there’s no images
Am thinking, if am using multiple pictures in my bundles… so i can call it by the name