Sign Up! Login: Password: New User? Forgot? Support
Code 
 
 
Forums 
Forums : Layout & Theme > Welcome User in Content Box Title
Mottie (SuperAdmin) 11/6/2009 12:30 AM EST : Welcome User in Content Box Title
ACK!
Mottie
Posts: 3884

0
Like

0
Dislike

Welcome User in Content Box Title

GuildPortal admin site link to the original post

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.


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!
Characters: Mottie Motty Mortie Ooshiny Mot Fudgems
TopBottom

Cerraherro (Member) 7/26/2010 12:46 PM EST : RE: Welcome User in Content Box Title
Cerraherro
Posts: 18

0
Like

0
Dislike

Hey Mottie I notice you've done this for the interior body of the Welcome content box but can't quite figure how you did it. Can you enlighten me? I am real new at this stuff but a quick study so hopefully I get it right the first time. Thx.
TopBottom

Mottie (SuperAdmin) 7/26/2010 1:02 PM EST : RE: Welcome User in Content Box Title
ACK!
Mottie
Posts: 3884

0
Like

0
Dislike

Hi Cerraherro!

GuildPortal has some block elements that are automatically replaced with information before the server sends the information to your browser. In the code above you will see:
$block[username]
This block element is replaced with "Mottie" in my case. The code above just hides this string and uses it to replace the widget title.

There is also a block element for a forum handle ($block[userhandle], of which mine is also "Mottie"). In fact there are a whole set of these block elements, which you can find in this post. Add them in free form text/HTML widgets or the Welcome widget.

In fact, now that I look at the code above again, I could shorten it substantially. And also use the forum handle instead of the name:
<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 + "$block[userhandle]" + suffix;
 $('#username').closest('div.ContentBox').find('.ContentBoxTitle,.ContentBoxTitleNoBackground').text(newtitle);
})
</script>
Characters: Mottie Motty Mortie Ooshiny Mot Fudgems
TopBottom

 
 
Key 
New posts No new posts
New posts ( popular ) No new posts ( popular )
New posts ( sticky ) No new posts ( sticky )
New posts ( locked ) No new posts ( locked )
 
 
Who's Online 
There are   members online.
 
 
So-and-so has logged on!
%title%
%message%