Certainly, here I’ll explain what I did below. One caveat though, I’m certainly no professional and I am fairly certain that there are more elegant/better ways to accomplish what I did. It is working for what I wanted though.
I’ve been extending the Gateway theme and in that theme there is a sidebar.html.twig that is useful for showing various things in a sidebar blog-like format.
As mentioned, I wanted to show an image that is associated with a category, in that sidebar, depending on what is being browsed next to it.
In most cases that would probably be a blog post (which would have 1 or more categories–though I only want the first) but it could also be if someone were to click on the category name to see all posts in the category. Furthermore, I’ve organized my site in 4 main topical sections (these are top level pages, with many child pages). Those sections do not have categories (because they’re at a “higher” hierarchy concept level) but they each have an icon that I want to appear in the place where a category image would otherwise have appeared in the sidebar. I added a metadata.section to those pages to help me distinguish them.
So, I put the following in my sidebar.html.twig and made a new template in partials/catimageassoc.html.twig that I use to associate each category (or section) with a specific image.