# Retrieving a "Resource" back from a string which matches the resource path?

**URL:** <https://discourse.gohugo.io/t/retrieving-a-resource-back-from-a-string-which-matches-the-resource-path/32048>\
**Category:** support\
**Created:** [March 29, 2021, 9:23pm UTC](https://discourse.gohugo.io/t/retrieving-a-resource-back-from-a-string-which-matches-the-resource-path/32048 "2021-03-29T21:23:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bravcmo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bravcmo/32/13985_2.png) [@bravcmo](https://discourse.gohugo.io/u/bravcmo)\
**Post date:** [March 29, 2021, 9:23pm UTC](https://discourse.gohugo.io/t/retrieving-a-resource-back-from-a-string-which-matches-the-resource-path/32048/1 "2021-03-29T21:23:16Z")

</div>

It was helpful to get [this response](https://discourse.gohugo.io/t/getting-page-resources-images-such-that-they-can-be-resized/32033) yesterday and now I understand that Page Resources can be called upon even if they aren’t referenced in the frontmatter of the index.md. My next question is relevant if I want to add metadata to the photos I retrieved with resources. In this case I have a gallery parameter where I associate images with descriptions like so:

```auto
gallery:
    - src: "am-red.JPG"
      description: Send it baby
    - src: am-kite-sbend.jpg
      description: "whatever"
    - src: alessio-foil.jpg
      description: "gnarly"

```

But now I just have string returned from “ranging” those gallery images. How do I use that string to return a “resource” which can be resized and such? I’ve tried the following but am receiving errors which are indicating that those methods are not available.

```auto
                                {{ $name := .File.Dir}}

                                   {{ range .Params.gallery }}
                                   {{ $resourceString := (printf "/%s%s" ($name) (.src))}}
                                   {{ $resourceString }}
                                   {{ $img := .Resources.Match $resourceString }}
                                   {{ $img := $img.Resize "x250" }}  
                                    <img src="{{ $img.RelPermalink }}" />
                                    <article class="article article-1 bg-image" style="background-image: url('{{ $img.RelPermalink }}');">
                                        <a href="#" target="_blank" class="article-link"></a>
                                        <div class="caption">
                                            <a href="#" class="article-title" target="_blank"><h2>{{ .Parent.Name }}</h2></a>
                                            <div class="entry-meta">
                                                <span class="published">Yesterday</span>
                                                <span class="posted-by">- By <a href="#" title="View all posts by Admin">Admin</a></span>
                                                <span class="posted-in">- in <a href="#" title="View all posts in Holiday">Holiday</a></span>
                                            </div>
                                        </div>
                                    </article>
                                {{ end }}

```

Thanks in advance for your time and help!

---

<div class="post-metadata">

**Author:** ![bravcmo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bravcmo/32/13985_2.png) [@bravcmo](https://discourse.gohugo.io/u/bravcmo)\
**Post date:** [March 29, 2021, 11:15pm UTC](https://discourse.gohugo.io/t/retrieving-a-resource-back-from-a-string-which-matches-the-resource-path/32048/2 "2021-03-29T23:15:51Z")

</div>

I may have achieved it. Feedback welcomed on if this is the preferred method. Related, I’m realizing that even upon retrieving the resized background image, all that appears in my `style` attribute in my html is a strange string `style='ZgotmplZ'`. Which is strange because I’m able to print out the full path and access it directly in my browser …

```auto
                                {{ $name := .File.Dir}}
                                {{ range .Params.gallery }}
                                    {{ $resourceString := (printf "/%s%s" ($name) (.src))}}
                                    {{ $img := $.Resources.GetMatch .src }}
                                    {{ $img := $img.Resize "x100" }}  
                                    {{ $styleString := printf "background-image: url('%s');" $img.RelPermalink }}
                                    {{ $styleString }}
                                    <article class="article article-1 bg-image" style={{ $styleString }}>
                                        <a href="#" target="_blank" class="article-link"></a>
                                        <div class="caption">
                                            <a href="#" class="article-title" target="_blank"><h2>caption here</h2></a>
                                            <div class="entry-meta">
                                                <span class="published">Yesterday</span>
                                                <span class="posted-by">- By <a href="#" title="View all posts by Admin">Admin</a></span>
                                                <span class="posted-in">- in <a href="#" title="View all posts in Holiday">Holiday</a></span>
                                            </div>
                                        </div>
                                    </article>
                                {{ end }}

```

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [March 30, 2021, 12:01am UTC](https://discourse.gohugo.io/t/retrieving-a-resource-back-from-a-string-which-matches-the-resource-path/32048/3 "2021-03-30T00:01:57Z")

</div>

```auto
<article class="article article-1 bg-image" {{ printf "style=%q" $styleString | safeHTMLAttr }}></article>

```

[https://gohugo.io/functions/safehtmlattr/](https://gohugo.io/functions/safehtmlattr/)

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [March 30, 2021, 12:09pm UTC](https://discourse.gohugo.io/t/retrieving-a-resource-back-from-a-string-which-matches-the-resource-path/32048/4 "2021-03-30T12:09:50Z")

</div>

> [@bravcmo](#):
>
> all that appears in my `style` attribute in my html is a strange string `style='ZgotmplZ'` .

This is one of the reasons to love Golang. Google that weird term 😉 It’s un-mis-understandable what this is about.
