0

I've added a content block via the administration panel, and placed and themed it - but now I realise I need to add some extra logic to output different things depending on what user is logged in.

What hook would I use to do this, and does using a hook guarantee it will overwrite whatever content has been put in via the Block admin panel?

3 Answers 3

0

You can try hook_block_list_alter() hook.

Act on blocks prior to rendering.

This hook allows you to add, remove or modify blocks in the block list. The block list contains the block definitions, not the rendered blocks. The blocks are rendered after the modules have had a chance to manipulate the block list.

You can also set $block->content here, which will override the content of the block and prevent hook_block_view() from running.

0

You are trying to overwrite output based on the user type whereas the right thing to do would be build the right output based on the user. So if it is a views block, its visibility should depend on the user role. That way, you build different solutions for different roles and never have to rewrite the output.

2
  • I see what you're saying - create two blocks, and control visibility via the Roles visibility settings in the block config page?
    – njp
    Feb 16, 2013 at 11:42
  • yes, exactly... Feb 17, 2013 at 11:33
0

Easiest way is hook_block_view_alter this hook will give you ability to override output of any block.

you can set condition based on user login like :

function mymodule_block_view_alter(&$data, $block) { if($block->bid == 41){ if($user->uid == 0){ $body = "your design without login"; $data["content"] = $body; }else{ $body = "your design with login"; $data["content"] = $body; } } } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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