Assets only available to SCSS not JS

Hello,

For the last week or so I’ve been styling a Discourse setup for a brand which includes fixed fonts, logos and icons.

To begin with I noticed that any assets I imported (place in assets folder and import under the assets object of about.json) became immediately available to use as a SCSS variable but took a minute or two to show up in settings.theme_uploads.

Now however, they don’t show up at all in settings.theme_uploads which means I can’t use them in my JavaScript. If I remove an asset it also stays in the settings object. The SCSS usage stays unaffected.

Help would be greatly appreciated.

1 个赞

是的,我也对这个问题有点困惑。

什么时候可以在 JavaScript 中安全地使用诸如 return settings.theme_uploads.blah 这样的引用,如果可以的话?

在我的计算属性中,我得到 settings.theme_uploads 为“undefined”(至少一开始是这样)。

这里的正确模式是什么?

1 个赞

settings.theme_uploads 数据是最近才添加到 javascript 中的(我认为是在 OP 编写之后)。它应该是可靠的——我们在自己的主题/组件中也使用它。你能更详细地解释一下你遇到的问题吗?

3 个赞

Ah, I was missing the assets folder in my path to the asset, so the broken link had “optimised out” the asset no doubt:

{
  "name": "Cool Theme Component",
  "about_url": "",
  "component": true,
  "assets": {
    "background": "background.png"
  }
}

should have been:

{
  "name": "Cool Theme Component",
  "about_url": "",
  "component": true,
  "assets": {
    "background": "assets/background.png"
  }
}

Doh!

FYI I’m reference this in Javascript in an Ember Component, e.g.:

  @computed
  backgroundImage() {
    return settings.theme_uploads.background;
  }

That would raise an undefined error when the path is incorrect!

Thanks for listening! @david, sorry to waste your time.

@hakonbja did you solve your issue?

2 个赞