Get page resources by name - front matter

front matter has this resources settings:

resources:
- name: banner
  source: /banners/post-ad-example.webp
  params:
    category: category-name
    target_url: /internal-page/

post template code snippet:

          {{ with .Resources.Match "banner" }}
          <div class="mxd-sidebar mxd-grid-item mxd-post-ad">
            <div class="mxd-sidebar__widget radius-m widget-ad">

              <a class="widget__image" href="{{ .Params.target_url | default "site.BaseURL"}}" aria-label="{{ .Params.category | default "News" }}">

                <img src="{{ .RelPermalink }}" alt="{{ .Params.category | default "News" }}">

              </a>

              {{ if isset .Params "category" }}
              <div class="widget__tags">
                <span class="tag tag-default tag-permanent">{{ .Params.category }}</span>

              </div>
              {{- end }}
            </div>
          </div>
          {{- end }}

Banner images are under /static/banners/

I can not fetch resources set in front matter under resources

How to fix it?

a page resource is a non content file within the page folder.

a static file is not a resource.

guess you want to place the file in assets and use the global resource function. if you only need that on one page, move it to the page folder

check the respective manual pages.

I want to use resources info in FrontMatter for images in static or assets folder.

the resources frontmatter field is for page resources. (Check the docs) If you want to load stuff from somewhere else, I will have to implement your own logic.

page/index.md
page/filename.webp
# or
page/images/filename.webp

will work with

name: 'banner'
src: 'filename.webp'
# or
src: 'images/filename.webp'

and again anything taken from /static is in no way a resource

1 Like