1

I understand how to preprocess a specific block to make some variable available for that it, but what I don't understand is where I grab these variable that I want to be available in my block.

I have the following code:

function THEME_preprocess_block(&$variables) {
    $variables['user_profile']= $user_profile; 
}

$user_profile is NULL.

So in other terms what i would like is to grab all the data entered by a user during the registration and make it available within block under for instance a user_profile variable. Is it possible at all?


Well i tried but it doesn't seem to do anything in drupal 7. Also isn't the user variable holding data only for the current loged in user ? I would like to retrieve the data of any user in order to populate the profile page with it.

2

You need to use the global user object to get info about the currently logged in user, then pass that user object to profile_load_profile:

function THEME_preprocess_block(&$variables) {
    global $user;
    $user_profile = profile_load_profile($user); 
    $variables['user_profile']= $user_profile; 
}

(code is untested but should work)

0

Here is the correct snipet:

function THEME_preprocess_block(&$variables) {
    $variables['user_profile'] = menu_get_object('user');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.