# 환영/재방문 배너 코드가 작동하지 않나요?

**URL:** https://meta.discourse.org/t/welcome-welcome-back-banner-code-not-working/284446
**Category:** Development
**Created:** [10월 26, 2023, 3:49오전 UTC](https://meta.discourse.org/t/welcome-welcome-back-banner-code-not-working/284446 "2023-10-26T03:49:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kynic](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@kynic](https://meta.discourse.org/u/kynic)
#### Post date: [10월 26, 2023, 3:49오전 UTC](https://meta.discourse.org/t/welcome-welcome-back-banner-code-not-working/284446/1 "2023-10-26T03:49:49Z")

</div>

> [@Display username when login in banner](https://meta.discourse.org/t/display-username-when-login-in-banner/83024/10):
>
> It looks like you copied the wrong code. This is what you want to add to \</head\> tab: \<script type="text/discourse-plugin" version="0.8.18"\> api.onPageChange(() =\> { if(api.getCurrentUser() != null) { $("#logged-in-user").text(" " + api.getCurrentUser().name.split(' ')[0]); } }); \</script\> And place this in the After Header tab where appropriate: \<h2 class="x-title"\>Hey\<span id="logged-in-user"\>\</span\>! Bienvenue dans ta nouvelle communauté\</h2\>

이 방법을 시도해 보았지만 사용자 이름이 표시되지 않습니다.

왜 이제 작동하지 않는지 확인해 주실 수 있을까요? 🙂

이 기능을 사용하고 싶습니다. 🙂

---

<div class="post-metadata">

### Author: ![Don](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/don/32/228726_2.png) [@Don](https://meta.discourse.org/u/Don)
#### Post date: [10월 29, 2023, 1:52오후 UTC](https://meta.discourse.org/t/welcome-welcome-back-banner-code-not-working/284446/2 "2023-10-29T13:52:22Z")

</div>

안녕하세요 @kynic 👋

여기서 잘 동작하나요?

이름이 사용 가능한 경우 이름을 표시하고, 사용자 이름만 사용 가능한 경우 사용자 이름을 표시합니다.

위 예제와 동일한 상태를 유지하기 위해 🔽

Header

```xml
<script type="text/discourse-plugin" version="0.8">
  api.onPageChange(() => {
    if (api.getCurrentUser()) {
      const loggedInUser = document.getElementById("logged-in-user");
      if (api.getCurrentUser().name) {
        loggedInUser.innerText = "Hey " + api.getCurrentUser().name + "!";
      } else {
        loggedInUser.innerText = "Hey " + api.getCurrentUser().username + "!";
      }
    }
  });
</script>

```

After Header

```xml
<h2 class="x-title"><span id="logged-in-user"></span> Bienvenue dans ta nouvelle communauté</h2>

```

도움이 되길 바랍니다. 🙂

---

<div class="post-metadata">

### Author: ![kynic](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@kynic](https://meta.discourse.org/u/kynic)
#### Post date: [10월 29, 2023, 8:18오후 UTC](https://meta.discourse.org/t/welcome-welcome-back-banner-code-not-working/284446/3 "2023-10-29T20:18:29Z")

</div>

안녕하세요,

로컬 호스트에서 이 기능을 테스트해 보고, 사용자 프로필에 전체 이름을 입력하자 해당 이름이 표시되기 시작했습니다. 그런데 전체 이름을 입력하지 않아도 정상적으로 작동해야 하는 건가요?

어쨌든, 프로덕션 사이트에서는 잘 작동하고 있습니다.

---

<div class="post-metadata">

### Author: ![kynic](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@kynic](https://meta.discourse.org/u/kynic)
#### Post date: [11월 5, 2023, 4:44오전 UTC](https://meta.discourse.org/t/welcome-welcome-back-banner-code-not-working/284446/4 "2023-11-05T04:44:56Z")

</div>

로그인한 사용자에게는 `user name`과 함께 "다시 오신 것을 환영합니다"를, 로그인하지 않은 사용자에게는 "환영합니다"를 표시하고 싶습니다.

도와주실 수 있나요?

---

<div class="post-metadata">

### Author: ![carson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/carson/32/280685_2.png) [@carson](https://meta.discourse.org/u/carson)
#### Post date: [11월 5, 2023, 4:55오전 UTC](https://meta.discourse.org/t/welcome-welcome-back-banner-code-not-working/284446/5 "2023-11-05T04:55:14Z")

</div>

현재 로그인된 사용자가 없으면 "Welcome"를 반환하도록 JavaScript를 수정하세요.

```plaintext
<script type="text/discourse-plugin" version="0.8">
  api.onPageChange(() => {
    const loggedInUser = document.getElementById("logged-in-user");
    if (api.getCurrentUser()) {
      if (api.getCurrentUser().name) {
        loggedInUser.innerText = "Hey " + api.getCurrentUser().name + "!";
      } else {
        loggedInUser.innerText = "Hey " + api.getCurrentUser().username + "!";
      }
    } else {
      loggedInUser.innerText = "Welcome"
    }
  });
</script>

```
