When creating a new block or altering an existing one, inside the block configuration interface, snippets of PHP code can be written to determine whether or not a block should be displayed.

 

Two of the most common snippets as follow:

Displaying a block to logged-in users only

Only return TRUE when the global $user is not 0.

<?php

global $user;

return (bool) $user->uid;

?>


Displaying a block to anonymous users only

Only return TRUE when the global $user is 0.

<?php

global $user;

return !(bool) $user->uid;

?>

 

Each snippet will return a TRUE or FALSE as the condition for which the block is made visible.

0
Your rating: None
Navigation
Syndicate
Syndicate content
Share this
Powered by Drupal, an open source content management system