How add username to panel header?
-
Hello
Please help me, how to show username in panel header?
I try
Welcome, {{username}}
it’s not work.
Example, when user log in to forum, he is view welcome banner (panel) with text “Welcome to forum @Username”
-
@maiseu I think @phenomlab did something similar to this
-
@dunlix I did, yes, but it's usage case is somewhat restricted without creating a plugin - see https://community.nodebb.org/topic/16052/widget-code-works-on-one-nodebb-instance-but-not-another/2?_=1635504604510
-
@phenomlab I need add to panel this code, yes?
<div class="mypanel123">Welcome to forum, <a href="/me"><span class="username">{user.username}</span></a></div>
-
@maiseu Yes, but it probably won't work because of the issues I raised in the post I referenced.
-
This should work if you don't want to write a plugin to provide the
user
object.<div class="mypanel123">Welcome to forum, <a href="/me"><span class="username"></span></a></div> <script> function updateUsername() { $('.mypanel123 .username').text(app.user.username); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', updateUsername); } else { updateUsername(); } </script>
-
-
-
On latest version of NodeBB you no longer need the js code, since the logged in user is provided in the
loggedInUser
object. So you can use the below html widget.<div class="mypanel123">Welcome to forum, <a href="/me">{loggedInUser.username}</a></div>
-