다시 인사드립니다. 답변해 주셔서 정말 감사합니다!
이것은 현재 작동하는 비권장(deprecated) 코드이며, 테마 컴포넌트의 <head> 섹션에 붙여 넣습니다. 지원용 CSS도 있지만, 여기서는 문제가 되지 않습니다.
<script type="text/discourse-plugin" version="0.8">
api.decorateWidget("post:after", helper => {
const firstPost = helper.attrs.firstPost;
const h = helper.h;
if (firstPost) {
let images = new Array();
let goTo = new Array();
/////////////////////////////////
let imageCount = 2;
images[0]="/uploads/3213123123123213.jpg";
goTo[0]="https://example1.com";
images[1]="/uploads/djdsalklkjdsajsalkd.jpg";
goTo[1]="https://example2.com";
/////////////////////////////////
imageCount-=1;
let randPick = Math.round(imageCount * Math.random());
let theLink = goTo[randPick];
let theImage = images[randPick];
return h("div.p3-image", [
h(
"a.p3-image-link",
{ href: theLink, target: "_blank" },
h("img", { src: theImage})
)
]);
}
});
</script>
필요한 것과 비슷한 일을 수행하는 최신 방법의 코드 스니펫을 계속 검색하고 수정해 보았는데, 현재까지 이렇게 작동하게 만들었습니다. JS 탭에 붙여 넣었습니다:
import Component from "@glimmer/component";
import { withPluginApi } from "discourse/lib/plugin-api";
function customizePost(api) {
api.renderAfterWrapperOutlet(
"post-article-content",
class extends Component {
static shouldRender(args) {
return args.post?.post_number === 1;
}
<template>Hello is this working? Yes but CSS divs are needed...</template>
}
);
}
export default {
name: "not-sure-if-I-need-this",
initialize() {
withPluginApi((api) => {
customizePost(api);
});
}
};
다음과 같은 코드를 시도해 보세요:
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { apiInitializer } from "discourse/lib/api";
export default apiInitializer((api) => {
api.renderAfterWrapperOutlet(
"post-article-content",
class extends Component {
@tracked imageSrc = "";
@tracked imageHref = "";
constructor() {
super(...arguments)
this.randomImageLink();
}
static shouldRender(args) {
return args.post?.post_number === 1;
}
randomImageLink() {
let images = new Array();
let goTo = new Array();
/////////////////////////////////
let imageCount = 2;
images[0]="/uploads/3213123123123213.jpg";
goTo[0]="https://example1.com";
images[1]="/uploads/djdsalklkjdsajsalkd.jpg";
goTo[1]="https://example2.com";
/////////////////////////////////
imageCount-=1;
let randPick = Math.round(imageCount * Math.random());
this.imageSrc = goTo[randPick];
this.imageHref = images[randPick];
}
<template>
<div class="p3-image">
<a href={{this.imageHref}} target="_blank">
<img src={{this.imageSrc}} />
</a>
</div>
</template>
}
);
});
조금 더 수정해야 할 수도 있습니다. 테스트를 해보지 않았기 때문입니다.
답장 늦어서 죄송합니다. 요즘 일이 좀 많아서요.
정말 좋습니다!! 작동하긴 하는데, 이 두 줄이 뒤바뀌어 있었네요:
this.imageSrc = images[randPick];
this.imageHref = goTo[randPick];
@tracked에 대해 좀 공부해 봐야 할 것 같아요 (이걸 뭐라고 불러야 할지조차 모르겠네요. 추적 변수라고 불러야 하나요?). 그리고 constructor 메서드도 마찬가지입니다. 또한 shouldRender 메서드가 어떻게, 그리고 언제 실행되는지 정확히 이해가 되지 않습니다.
이 부분에 대해 정말 많이 도와주셔서 감사합니다. 저 혼자라면 이 메서드들을 사용해야 한다는 걸 절대 몰랐을 겁니다.
추적(tracked) 속성에 대해 여기 에서 자세히 읽을 수 있습니다.
shouldRender는 템플릿이 표시되는지 여부를 결정하기 때문에 시작 시점에 바로 실행된다고 생각합니다.
도움이 되었다니 기쁩니다!
Monikas
(JustMonika)
2월 2, 2026, 9:48오전
46
<script type="text/x-handlebars" data-template-name="/connectors/discovery-list-container-top/moe-counter-banner">
<div class="moe-counter-container">
<img
src="https://moe.8845.top/get/?name=Monika&theme=booru-helltaker"
alt="Visitor Counter"
class="moe-counter-img"
>
</div>
</script>
이걸 어떻게 작성해야 할까요? 저도 여기서는 초보입니다.
다음과 같이 시도해 보세요:
api.renderInOutlet(
"discovery-list-container-top",
<template>
<div class="moe-counter-container">
<img
src="https://moe.8845.top/get/?name=Monika&theme=booru-helltaker"
alt="Visitor Counter"
class="moe-counter-img"
>
</div>
</template>
);
참고:
Discourse uses the Ember JS Framework for its user interface. On top of Ember, Discourse provides a number of APIs to allow themes to customize the user interface. The most commonly-used API is Plugin Outlets.
These outlets are positioned throughout Discourse core, and allow themes to render Ember Components inside them. Those components are given access to some contextual information called “outlet args”.
Some outlets also “wrap” part of the core user interface, which allows themes to add the…
david
(David Taylor)
3월 25, 2026, 10:46오전
49
david:
2025년 5월 - 콘솔 비추천 메시지 활성화
2025년 7월 - 관리자 경고 배너 활성화
2025년 9월 말 2026년 3월 - 기능 제거
이 인라인 스크립트 태그에 대한 지원은 최신 버전의 Discourse에서 이제 제거되었습니다.
main ← drop-script-tag
merged 10:49AM - 25 Mar 26 UTC
These were deprecated in May 2025. https://meta.discourse.org/t/modernizing-inli… ne-script-tags-for-templates-js-api/366482