How do I use images from assets in HTML of a Glimmer-based theme component?

Include assets (e.g. images, fonts) in themes and components seems to still refer to the handlebars way of doing things, if I’m grasping it correctly. Is the new Glimmer way already available for getting images from the theme component’s assets directory usable in an HTML(-template) of the same theme component?

My use case is to replace the now-broken legacy theme component described in Templating of my "component" broke. How do I fix it?.

What I've tried

I’ve generated a new theme component project with discourse_theme new discourse-tc-geowebforum-sponsors and then tried to replicate the previous plugin without the conditional logic and with an inline template, but that lead to

[THEME 6 'geowebforum-sponsors'] Error: [THEME 6 'geowebforum-sponsors'] Compile error: SyntaxError: /theme-6/discourse/api-initializers/geowebforum-sponsors.gjs: Attempted to resolve a helper in a strict mode template, but that value was not in scope: theme-relative-url: 

in the browser console.

I’ve also various combinations of:

  • pulling the template out into a constant
  • single (instead of double) curly braces
  • using a function call (themeRelativeUrl("asseco_berit.jpg")) within the curly braces
  • moving the template to javascripts/discourse/components/geowebforum-sponsors.gjs (and importing it from the initializer)
  • moving the template to javascripts/components/geowebforum-sponsors.gjs (and importing it from the initializer)
  • introducing a class GEOWebforumSponsorsComponent extends Component {} in that file and importing that in the initializer (while exporting the template from the same file as the class under name template, as an LLM had suggested to me – I’m still unsure whether that would make any sense.)

I either got

  • the same error (albeit from that other file)
    or
  • klass is not an Ember component
    or
  • literal template placeholders in the resulting DOM, naturally leading to 404s for the image sources
1 like

Hmm, did you see this bit?