テーマ開発者クイックリファレンスガイド

テーマが強力になるにつれて、その動作について覚えておくべきことが増えてきます。ここには#howto / #themes の下に詳細なドキュメントがたくさんありますが、記憶を呼び覚ますためだけに何かが必要な場合は、このガイドが役立つかもしれません。

一般的なリソース

:scroll: 初心者ガイド
:scroll: デザイナーガイド
:scroll: 開発者ガイド
:paintbrush: テーマクリエーター
:desktop_computer: テーマCLI
:notebook_with_decorative_cover: テーマディレクトリ
:jigsaw: コンポーネントディレクトリ
:wrench: テーマモディファイア
:wrench: テーマ設定可能なサイト設定

ファイル/フォルダ構造 続きを読む

about.json
settings.yml
common/, desktop/, mobile/
  {common|desktop|mobile}.scss
  head_tag.html
  header.html
  after_header.html
  body_tag.html
  footer.html
  embedded.scss (common のみ)
locales/
  en.yml
  ...
assets/
  (任意に命名されたファイル。about.json で参照されます)
stylesheets/
  (任意に命名されたファイル。お互いに、また common/desktop/mobile.scss からインポート可能)
javascripts/
  (任意に命名されたファイル。 .js .hbs および .raw.hbs をサポート)

about.json 構造情報, 利用可能なメタデータ

{
  "name": "My Theme",
  "component": false,
  "license_url": null,
  "about_url": null,
  "authors": null,
  "theme_version": null,
  "minimum_discourse_version": null,
  "maximum_discourse_version": null,
  "assets": {
    "variable-name": "assets/my-asset.jpg"
  },
  "color_schemes": {
    "My Color Scheme": {
      "primary": "222222"
    }
  }
}

SCSS

:link: 利用可能な CSS 変数

Javascript 続きを読む

// {theme}/javascripts/api-initializers/init-theme.gjs
import { apiInitializer } from "discourse/lib/api";

export default apiInitializer((api) => {
  // あなたのコード
});

:link: JS Plugin API

:link: マルチファイル Javascript

設定 続きを読む

settings.yml:

fruit:
  default: apples|oranges
  type: list
  description: # 古い方法。ロケールファイルで定義する方が良いです(下記参照)
    en: English Description
    fr: Description Française

JavaScriptからのアクセス:

console.log(settings.fruit);

gjsテンプレートからのアクセス:

<template>{{settings.fruit}}</template>

scssからのアクセス:

html {
  font-size: #{$global-font-size}px;
  background: $site-background;
}

テーマ設定可能なサイト設定 続きを読む

about.json:

"theme_site_settings": {
  "enable_welcome_banner": false
}

JavaScriptからのアクセス:

@service siteSettings;

this.siteSettings.enable_welcome_banner;

gjsテンプレートからのアクセス:

<template>{{this.siteSettings.enable_welcome_banner}}</template>

翻訳 続きを読む

locales/en.yml

en:
  my_translation_key: "I love themes"
  theme_metadata: # これらは管理パネルで使用されます。js/hbsファイルでは利用できません
    description: This theme lets you do amazing things on your Discourse
    settings:
      fruit: A description of the whitelisted_fruits setting

JavaScriptからのアクセス:

import { i18n } from "discourse-i18n";
i18n(themePrefix("my_translation_key"));

gjsテンプレートからのアクセス:

import { i18n } from "discourse-i18n";

<template>
  {{i18n (themePrefix "my_translation_key")}}
  <DButton @label={{theme-prefix "my_translation_key"}} />
</template>

このドキュメントはバージョン管理されています - 変更提案はgithubで。

「いいね!」 40

This is super useful.

Could I also suggest that a useful reference to add is the list of available color transformations:

「いいね!」 3

I must be missing something here, I’m trying to use I18n.t(themePrefix("my_translation_key")) but the Firefox console reports that themePrefix is undefined.
How can I invoke that function from an api function?

リンクが無効になっているようです。

「いいね!」 2

おっしゃる通りです。現在は以下のようになっています。

https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/lib/plugin-api.js

「いいね!」 2

@th21@Arkshine、ありがとうございます。リンクを更新しました。

「いいね!」 2

プラグインAPIのリンクが再び変更されました。

https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/lib/plugin-api.gjs

「いいね!」 2

ありがとうございます!更新しました :writing_hand:

「いいね!」 3