Sign Up! Login: Password: New User? Forgot? Support
Top Mods!
Wowhead Search
by sonofsamedi
Digital Clock
by Wolfar15
Admin Forums
Welcome to the GuildPortal Help Community! These forums are for admin-to-admin help.
Available Forums
Forums : Voodoo Tech and Scripter's Den of Scriptniquity > Welcome User in Content Box Title
Mottie (MVP) 11/6/2009 12:29 AM EST : Welcome User in Content Box Title
GuildPortal MVP
Mottie
Posts: 3884
Zomgawsh Poster

Welcome User in Content Box Title

This script will add the currently logged in user name with whatever message you choose to the Welcome box title. Actually any content box that you add this script in will change the have the user name added to the end. I haven't tested this, but I wouldn't add this more than once per page because it probably won't work as expected.



The Code
<div id="username" style="display:none;">$block[username]</div>
<script type="text/javascript">
$(document).ready(function(){
 var prefix = "Hey ";
 var suffix = ", welcome to our rockin' website!"
 
// don't change anything below
 var newtitle = prefix + $('#username').text() + suffix;
 $('#username').closest('div.ContentBox').find('.ContentBoxTitle,.ContentBoxTitleNoBackground').text(newtitle);
})
</script>
Customizing
  • Note that this script replaces the entire box title. In the screen shot above, the box title was "Welcome". The script changed it to "Hey {username}, welcome to our website!"
  • The variable named prefix will be added before the user name
  • The variable named suffix added the text after the user name, there really isn't that much to it.
  • Note: You can add HTML to the prefix and suffix variables (like <img>) if you wish.
TopBottom

Valdaglerion (Guild Admin) 11/22/2011 8:32 PM EST : RE: Welcome User in Content Box Title
Valdaglerion
Posts: 2473
Zomgawsh Poster

Would it be possible to specify a default name for those people who view the site when NOT logged in.  Something like "friend"?
TopBottom

Mottie (MVP) 11/23/2011 8:05 AM EST : RE: Welcome User in Content Box Title
GuildPortal MVP
Mottie
Posts: 3884
Zomgawsh Poster

Ok, here is method #2... basically this version allows you to add [user] to any widget and it replaces it with the user name. If the user name is "Guest" then it replaces it with whatever name you have in the defaultName variable.

 Before 

After

*Note: The Mottie in the message below the title was added via the standard method of using "$block[username]" - Hello $block[username] & Welcome...

Code
<div id="username" style="display:none;">$block[username]</div>
<script type="text/javascript">
$(function(){
    // replaces "Guest", if someone isn't logged in
    var defaultName = "friend";

    // Don't change anything below
    // ***************************

    var user = $('#username').text();
    user = (user === "Guest") ? defaultName : user;
    $('.ContentBoxTitle,.ContentBoxTitleNoBackground').each(function(){
        $(this).text(function(i,t){
            return t.replace(/\[user\]/g, user);
        });
    });
});
</script>
Customizing
  • Change any widget titles by editing the widget, then clicking on the underlined "Widget Title" in the upper right corner.
  • Add "[user]" where ever you want the user name to appear
  • Click the [ Update Title ] button
  • Add the above code to your header or footer area (Control Panel > Custom HTML & Script > Footer Area) - I would say it is preferred to put this script in the header area (subscribed guilds) because the script runs sooner. Otherwise the [user] doesn't get changed until the page has loaded the content - it may be noticeable.
  • Modify the defaultName (in blue) with whatever default name you want guests (people not logged in) to see - be nice!
TopBottom

Valdaglerion (Guild Admin) 11/24/2011 1:45 PM EST : RE: Welcome User in Content Box Title
Valdaglerion
Posts: 2473
Zomgawsh Poster

Thanks for updating this Mottie.  The only issue I've noticed is that it only changes the title, which is probably as intended.  I added the script to the Welcome content widget and it works for the title.  "[user]" doesn't work in the body of the message, though, it still shows "[user]".  "$block[username]" works but shows "Guest" if they are not logged in.
TopBottom

Mottie (MVP) 11/24/2011 5:32 PM EST : RE: Welcome User in Content Box Title
GuildPortal MVP
Mottie
Posts: 3884
Zomgawsh Poster

Oh, you didn't say you wanted it to work inside the widget as well... try this code:
<div id="username" style="display:none;">$block[username]</div>
<script type="text/javascript">
$(function(){
    // replaces "Guest", if someone isn't logged in
    var defaultName = "friend";

    // Don't change anything below
    // ***************************

    var user = $('#username').text();
    user = (user === "Guest") ? defaultName : user;
    $('.ContentBoxTitle,.ContentBoxTitleNoBackground,.ContentBoxBody').filter(':contains("\[user\]")').each(function(){
      // abort if the element contains a script tag
      if (!$(this).find('script').length) {
        $(this).html(function(i,t){
          return t.replace(/\[user\]/g, user);
        });
      }
    });
});
</script>
Edit: Updated to prevent problems with script tags inside of the widget.
TopBottom

Valdaglerion (Guild Admin) 11/26/2011 3:16 PM EST : RE: Welcome User in Content Box Title
Valdaglerion
Posts: 2473
Zomgawsh Poster

That works!  Thanks Mottie!
TopBottom

Admins Online
There are   members online.
So-and-so has logged on!
%title%
%message%