Block Visibility in Drupal

0
Your rating: None

Inside the block admini interface, one can enter PHP code snippets in “Page visibility settings” section of the block configuration page.
While a page being generated, Drupal will run the PHP snippet to determine whether a block will be displayed.

Examples of some of the most common snippets follow; each snippet should return TRUE or FALSE to indicate whether the block should be visible for that particular request.

Displaying a Block to Logged-In Users Only
Only return TRUE when $user->id is not 0.

<?php
   global $user;
   return (bool) $user->uid;
?>

Displaying a Block to Anonymous Users Only
Only return TRUE when $user->uid is 0.

<?php
   global $user;
   return !(bool) $user->uid;
?>

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Cumulus Tag Cloud

Kiran Says

SEO Architect,SEO Specialist reflect my values.

By enduring black hat methods the SEO industry is setting itself up for washout and sleepwalking into oblivion.

Jobs in India