Change the default folder of the resources.Get parameter

{{ $image := resources.Get "images/logo.jpg" }}
{{ with $image }}
  <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
{{ end }}

The code above brings me the logo.jpg file in the images folder under the assets folder.

I want to make this assets folder a static folder.

How can I do that?

1 Like

You cannot process images in the static folder. Only from assets.

BUT you can mount static as assets with something like this :

[module]
    [[module.mounts]]
        source = "static/img_as_assets"
        target = "assets/img_from_static"

And then use:

{{ $image := resources.Get "img_from_static/logo.jpg" }}

Hugo is a real magic tool for anything (except may be a good Italian expresso)

2 Likes

Thank you for your answer, but unfortunately the {{ $image := resources.Get "img_from_static/logo.jpg" }} part did not work

1 Like

Can you show ALL your code. It is impossible to guess what goes wrong

But you have the idea : mount your static folder like it was an assets folder.

And then all under static is magically like an assets resource

2 Likes

obviously you have to put the logo.jpg inside the img_as_assets folder or adapt the mount directive.

I hope you understood this.

2 Likes

config.toml file:

[module]
  [[module.mounts]]
    source = "static/img_as_assets"
    target = "assets/img_from_static"

single.html file:

{{ $image := resources.Get "img_from_static/images/logo.jpg" }}
{{ with $image }}
  <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
{{ end }}

folder structure:

image

I don’t necessarily have to solve the problem with this parameter, I just need a code that I can get the size and width of the images in my static folder.

1 Like

you didn’t read my response. Your folder stucture is wrong (or the mount directive)

2 Likes

I really don’t know exactly what to do. Can you give me an example?

1 Like
- assets
- static
  * static/img_as_assets

but you really need to read the Hugo folder organisation documentation.

2 Likes

Yes, now I understand the logic. I look at the texts from the translation because my English is not enough, so I did not understand what you said at first. Thank you for your help.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.