Scratch doesn't works on print?


I want to have my images filenames hashed. Not my project, so not my call. But they want them hashed, so I’m doing it. The trick is they still want to able to write internally the file name.

So, in this case, a file named "hello moto.jpg will be hashed and saved as "ed10ede60cf247931c3a8b8b3f34b84630efda70" to the assets folder.

Now, we want them to still be able to write the image name in the front matter, like this:

Title: "Hello Motorola, how are you?"
article_img: "hello moto"

Then, through a partial, we want to detect that image’s name and replace it with the real hashed name.

This should work, but it doesn’t. It keeps giving me the following error:

Execute of template failed at <resources.Get>: error calling Get: GetFileAttributesEx C:\hugo\motorola\images\<nil>.jpg:

The image is there, no idea why it returns NIL. Something happens when we try to take the string out of the IF with Scratch

{{ if .Params.article_img }}
	{{ if eq .Params.article_img "hello moto" }}        
 		{{ .Scratch.Set "hash_name" "ed10ede60cf247931c3a8b8b3f34b84630efda70" }}        
	{{ end }}

	{{ $image_name := .Scratch.Get "hash_name" }}
	{{ $image_name }}

	{{ $base := print .Section "/images" }}
	{{ $path := print $image_name }}
	{{ $url := print $base "/" $path ".jpg" }}

	{{ $image := resources.Get $url }}
	{{ .Scratch.Set "image" $image.Permalink }}
{{ end }}

{{ $img := .Scratch.Get "image" }}

Here is the image: {{ $img.Permalink }}

Any ideas?