# How do I customise the styling of "solved topics" in the main list?

**URL:** https://meta.discourse.org/t/how-do-i-customise-the-styling-of-solved-topics-in-the-main-list/58379
**Category:** Support
**Tags:** solved
**Created:** [6월 30, 2015, 10:02오전 UTC](https://meta.discourse.org/t/how-do-i-customise-the-styling-of-solved-topics-in-the-main-list/58379 "2015-06-30T10:02:46Z")
**Posts on this page:** 1
**Showing post:** 12

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [10월 16, 2021, 2:14오전 UTC](https://meta.discourse.org/t/how-do-i-customise-the-styling-of-solved-topics-in-the-main-list/58379/12 "2021-10-16T02:14:14Z")

</div>

요약

이 방법은 답변으로 표시된 게시글에 `topic-solution` 클래스를 추가합니다.

```javascript
api.addPostClassesCallback((attrs) => {
  if (attrs.accepted_answer) return ["topic-solution"];
});

```

* * *

게시글이 가진 클래스는 여기서 결정됩니다.

> <https://github.com/discourse/discourse/blob/45a166b6efaca54f4f4ab6a492bc5b000ebc9920/app/assets/javascripts/discourse/app/widgets/post.js#L752>

원하시는 훅은 이미 해당 파일의 맨 끝에 다음과 같이 존재합니다.

> <https://github.com/discourse/discourse/blob/45a166b6efaca54f4f4ab6a492bc5b000ebc9920/app/assets/javascripts/discourse/app/widgets/post.js#L793-L800>

플러그인 API에는 조건에 따라 게시글에 클래스를 추가할 수 있는 메서드가 있습니다.

[https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/lib/plugin-api.js#L819-L829](https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/lib/plugin-api.js#L819-L829)

이 메서드는 주어진 콜백을 적용하고, 조건이 충족되면 추가할 클래스를 반환합니다.

콜백이 실행되면 Discourse는 게시글 속성을 전달합니다. 따라서 예를 들어 다음과 같은 작업을 수행할 수 있습니다.

```javascript
api.addPostClassesCallback((attrs) => {
  console.log(attrs);
});

```

콘솔을 확인하면 각 게시글의 속성이 표시되는 것을 볼 수 있습니다.

 ![image](https://global.discourse-cdn.com/meta/original/3X/4/f/4ffb2f909414f15459421371fbd4a3f644f69b81.png)

이것들은 단지 예시일 뿐이며, 더 많은 속성이 있습니다.

다행히도 게시글이 해결책으로 표시되면 Discourse가 이를 추적하고 게시글 속성에 추가합니다. 해당 속성은 `accepted_answer`라고 합니다.

따라서 해당 속성이 true인지 확인하고, true인 경우 사용자 정의 클래스를 추가하기만 하면 됩니다. 다음과 같이요.

```javascript
api.addPostClassesCallback((attrs) => {
  if (attrs.accepted_answer) return ["topic-solution"];
});

```

이것만으로 원포스터(OP)가 마음을 바꿔 다른 해결책을 선택하더라도 클래스가 전환됩니다. 이전 답변에서 클래스가 제거되고 새로운 답변에 추가됩니다.

---

_[View the full topic](https://meta.discourse.org/t/how-do-i-customise-the-styling-of-solved-topics-in-the-main-list/58379)._
