I tried this and it not showing the user name.
Can anyone take a look as why it is not working now?
I want to use it.
I tried this and it not showing the user name.
Can anyone take a look as why it is not working now?
I want to use it.
Hello @kynic
Is it works for you?
If name is available it shows the name if only username available it will shows the username.
Just to stay the current example above
Header
<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
<h2 class="x-title"><span id="logged-in-user"></span> Bienvenue dans ta nouvelle communauté</h2>
I hope this helps.
Hi,
I was testing this on my local host, and when I added my full name to the user profile, it started to show up. But should it also work without adding a full name?
Anyway, on the production site, it works well.
I want to show welcome back user name
to logged in users and welcome to non-logged in users.
Can anyone help?
Amend the Javascript to return “Welcome” if there is no current logged-in user—
<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>