I have a Quicktab with 2 tabs. The block is placed in user profile.

Now I want to show one of the blocks only when the user visits his own profile and hide it when he is visiting other profiles. How may I do this?


In Drupal 7 you can use hook_quicktabs_alter

     * Implementing hook_quicktabs_alter
     * @param type $quicktabs
    function MODULE_NAME_quicktabs_alter(&$quicktabs) {
        global $user;
        foreach ($quicktabs->tabs as $key => $tab) {
            if ($tab['title'] == 'Tab1' && arg(0) == 'user' && is_numeric(arg(1)) && $user->uid == arg(1)) {//check condition as per your requirement
  • Thanks, But this will affect both of the tabs of the quicktab. What i want is to be able to show only one of the tabs if the condition meet. – lameei Feb 10 '14 at 10:26
  • You mean to say you have only one block with 2 tabs. You want to hide the tab based on some requirement? – inizio Feb 10 '14 at 10:28
  • I have updated my answer. – inizio Feb 10 '14 at 10:42
  • Where should I put this? Shall I write a module? – lameei Feb 10 '14 at 10:52
  • Yes inside any custom .module file. If you dont have the custom module then create one. Use this link as reference OR Building a Drupal 7 Module – inizio Feb 10 '14 at 10:54

you would need to put that code right where you want the quicktab to render:

// Current user uid.
global $user;
$userUid = $user->uid;

// Uid of the user's viewed profile.
$userUidViewedProfile = $arg(1)

// Condition if current userId = userId's viewed profile. If it is, render the quicktab.
if ($userUid == $userUidViewedProfile)
    $block = module_invoke('quicktabs', 'block_view', 'machine_name'); // Only change the machine name here,
    print render($block);
  • This works for the whole block. I want one of the tabs to be checked like this. – lameei Feb 10 '14 at 5:00

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.