Get page resources for specific page

I am using page resources for all pages. For my navbar, I am using a logo which sits at the root of the content folder. When the user is on the home page, I am able to get the logo and it shows on the navbar but when the user navigates away, I am not longer able to get the logo (which is logical).

I would like to know how I can construct a function to always get the logo for the index page so that as the user navigates, the logo shows. I’ve tried a few different things and done google searches but I have not been successful. Would someone be able to point me in the right direction please?

I could be completely wrong, but, it looks like that’s not currently available?

One way that simply dodges your problem is: You could just put the logo in /static, like /static/img/mylogo.png and it would always be available to your templates at the url path /img/mylogo.png.

This is possible. You can do something like this in your template(s):

{{ $logo := (site.GetPage "/_index.md").Resources.GetMatch "logo.jpg" }}
<img src="{{ $logo.RelPermalink }}">

FYI this was tested on a project with content structure:

β”œβ”€β”€ content
β”‚   β”œβ”€β”€ _index.md
β”‚   β”œβ”€β”€ logo.jpg
β”‚   └── section-1
β”‚       └── page-1
β”‚           └── index.md
1 Like

Thanks. Cool solution.

1 Like

Thank you. I tested this and it worked immediately. I just pushed the change live.

1 Like