Posted by mark2741 on December 5, 2012 at 4:51am
I've been spending the last few nights building a simple social network using OG. I'm fairly new to Drupal but did take some online classes on it. Making great progress but am stumped on some things such as this one:
I'd like to create a small block that simply has the following text in it: "Welcome, John Doe!" < Where "John Doe" is the currently logged in user's ID/name from their profile.
How would I do that?
Comments
It depends on what "John Doe"
It depends on what "John Doe" is. Is it the username or something else. If the username you can use
global $user;if ( $user->uid ) {
print t('Welcome @name', array('@name' => format_username($user)));
}
user global $user
Its very simple you have declare global $user in your function and you can access $user object anywhere in your function eg:
<?php
//take any function ,Simply I have taken form function here
function test_form($form_state) {
global $user;
$user_name= $user->name;
$user_id = $user->uid;
// to see all the values of $user object just print it using dsm or drupal_set_message
drupal_set_message("<pre>".print_r($user,true)."</pre>");
}
?>
Without hard coding you can
Without hard coding you can use Trigger and Action (both are core modules).
ꦱꦠꦽꦶꦪ
Thanks for the replies. I'm
Thanks for the replies.
I'm trying to avoid any hard-coding at this point if possible and this is just a 'nice to have' feature for me. I think triggers/actions is likely the right path but let me clarify further what I'm trying to do in hopes to get some more advice:
I have a 'User Menu' in the left-sidebar that looks like this presently:
USER MENU
I'd like it to look like this:
Welcome, [USER]!
Where [USER} is the user's login ID/user name. Is there a way to do this without coding?
Thanks again.
Mark
I've done some further
I've done some further research and it appears that I should be able to accomplish what I'm trying to do easily by using the Token module, but it's not working. Here's what I've tried:
1. In the block's title, where it says in the help text that Tokens are allowed, I put:
Welcome back, [user:name]!
But when I go to save it it says that it's an invalid token. I've tried 3 or 4 different tokens and get the same error.
So then I tried just creating a new block and in the body, with Full HTML enabled, I put:
Welcome back, [user:name]!
and it just shows the token as plain text and not the actual token : (
You must create an advanced
You must create an advanced action > display a message to user>type your message to user-use token as you need.
Go to trigger >tab user >after user login>Assign your action.
Now every time user login, your message appear in Drupal status message.
ꦱꦠꦽꦶꦪ