Resource.get get an error as file doesn't exist...but it is!

Hello,
I’m developing a site with Hugo driven by data (.yaml file inside data dir). It’s quite complex but basically I have a lot of yaml file for each “piece” of html that I can put in the site.
For the image I put the image inside the assets directory and in the yaml file something similar to this:

Image:
    IsPresent: true
    ImageUrl: "img/mockup/homepage/contacts/contacts00/770x502/img01.png"
    ImageDescription: "Suspendisse tellus"

where inside the ImageUrl there is the path to the file. In the layout I put something like this:

{{ $img1 := resources.Get (string .data.Image.ImageUrl) }}

where .data is a variable passed to the partials when calling it. So far so good for a lot of “modules” of my website but for one of them it’s 2 days that I’m not figure out why it gives me error.
Well if I put this:

{{ $imagepath := .data.Image.ImageUrl}}
<H2>{{ $imagepath }}</H2>
{{ $img1 := resources.Get "img/mockup/homepage/contacts/contacts00/770x502/img01.png" }}
<h2>{{$img1.Permalink}}</h2>

it works like a charm and it render this:

If I change in this way:

{{ $imagepath := .data.Image.ImageUrl}}
<H2>{{ $imagepath }}</H2>
{{ $img1 := resources.Get (string $imagepath) }}
<h2>{{$img1.Permalink}}</h2>

that is pretty the same thing (as you can see the text variable contains the same text) it gives me a horrible error:

```
render of "page" failed: execute of template failed: template: misc/landing_pages_00.html:352:15: executing "main" at <partial "home_land/contacts/04_contacts" (dict "context" $.Site "data" $data)>: error calling partial: "C:\SourceCode\websites\hugo\template\Hugo_Themes\layouts\partials\home_land\contacts\04_contacts.html:3:21": execute of template failed: template: partials/home_land/contacts/04_contacts.html:3:21: executing "partials/home_land/contacts/04_contacts.html" at <resources.Get>: error calling Get: dirs not supported resource types: &{0xc00be7b1c0 map[baseDir:C:\SourceCode\websites\hugo\template\Hugo_Themes\ filename:assets fs:0xc0006d0c60 isOrdered:false lang: mountRoot: mountWeight:1 opener:0xc47640 watch:true]}
Rebuild failed:

Failed to render pages: render of "page" failed: execute of template failed: template: misc/landing_pages_00.html:352:15: executing "main" at <partial "home_land/contacts/04_contacts" (dict "context" $.Site "data" $data)>: error calling partial: "C:\SourceCode\websites\hugo\template\Hugo_Themes\layouts\partials\home_land\contacts\04_contacts.html:3:21": execute of template failed: template: partials/home_land/contacts/04_contacts.html:3:21: executing "partials/home_land/contacts/04_contacts.html" at <resources.Get>: error calling Get: dirs not supported resource types: &{0xc00fd17070 map[baseDir:C:\SourceCode\websites\hugo\template\Hugo_Themes\ filename:assets fs:0xc0006d0c60 isOrdered:false lang: mountRoot: mountWeight:1 opener:0xc47640 watch:true]}
```

```
github.com/gohugoio/hugo/hugolib.(*Site).renderPages
	/root/project/hugo/hugolib/site_render.go:105
github.com/gohugoio/hugo/hugolib.(*Site).render
	/root/project/hugo/hugolib/site.go:1091
github.com/gohugoio/hugo/hugolib.(*HugoSites).render
	/root/project/hugo/hugolib/hugo_sites_build.go:338
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build.func4
	/root/project/hugo/hugolib/hugo_sites_build.go:136
runtime/trace.WithRegion
	/usr/local/go/src/runtime/trace/annotation.go:137
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build
	/root/project/hugo/hugolib/hugo_sites_build.go:138
github.com/gohugoio/hugo/commands.(*commandeer).rebuildSites
	/root/project/hugo/commands/hugo.go:744
github.com/gohugoio/hugo/commands.(*commandeer).handleEvents
	/root/project/hugo/commands/hugo.go:1104
github.com/gohugoio/hugo/commands.(*commandeer).newWatcher.func1
	/root/project/hugo/commands/hugo.go:851
runtime.goexit
	/usr/local/go/src/runtime/asm_amd64.s:1357
```

It make me crazy because with the same technique in other part works without any problem.
Is somebody that can help me?

Hmm. My first time seeing this error message:

error calling Get: dirs not supported resource types:

I suspect you are not calling the partial properly.

Maybe you are doing this:

{{ partial "test.html" site.Data.foo }}

Instead of this:

{{ partial "test.html" (dict "data" site.Data.foo) }}

Try this:

git clone --single-branch -b hugo-forum-topic-32705 https://github.com/jmooring/hugo-testing hugo-forum-topic-32705
cd hugo-forum-topic-32705
hugo server
3 Likes

Hi,
thanks for the response. I think that I call the partial properly. Look here:

CONTACTS-00

I call the partial in this way:

 {{ if eq .element "CONTACTS-00"}}
         {{ partial "home_land/contacts/00_contacts" (dict "context" $.Site "data" $data) }}
 {{end}}

The template has this code:

{{if eq .data.Image.IsPresent true}}
     {{ $img1 := resources.Get (string .data.Image.ImageUrl) }}
     <div class="container text-center g-overflow-hidden">
         <img class="img-fluid" src="{{$img1.Permalink}}" alt="{{.data.Image.ImageDescription}}"  data-animation="slideInUp">
     </div>
{{end}}

And the YAML has this code:

Image:
    IsPresent: true
    ImageUrl: "img/mockup/homepage/contacts/contacts00/770x502/img01.png"
    ImageDescription: "Suspendisse tellus"

IT WORKS WITHOUT ANY PROBLEM

CONTACT-04

I call the partial in this way:

    {{ if eq .element "CONTACTS-04"}}
        {{ partial "home_land/contacts/04_contacts" (dict "context" $.Site "data" $data) }}
    {{end}}

The template has this code:

{{ $imagepath := .data.Image.ImageUrl}}
<H2>{{ $imagepath }}</H2>
{{ $img := resources.Get .data.Image.ImageUrl }}
{{ $img1 := resources.Get "img/mockup/homepage/contacts/contacts00/770x502/img01.png" }}
<h2>{{$img1.Permalink}}</h2>

And the YAML has this code:

Image:
    IsPresent: true
    ImageUrl: "img/mockup/homepage/contacts/contacts00/770x502/img01.png"
    ImageDescription: "Suspendisse tellus"

THERE IS NO WAY TO MAKE IT FUNCTION
It gives me the error that I put at the beginning of the post.

I try your branch and it works like my CONTACT-00 the question is why CONTACT-04 doesn’t work…there is some log or something other to see?

Please share the public repository for your project, privately if you wish.

Finally I find the solution!!!
Basically I use the same partial for two different part of the template layout (homepage and landingpage) so the .yaml file (the data files) are different for each part. I upgrade one .yaml but not the second one so when Hugo try to recompile didn’t find the file path and get this error. We can say that

error calling Get: dirs not supported resource types:`

means

I can't find the files you asked me to put as resource object...are you sure that it exist and the string passed is not empty?

Thanks to all for the support provided