Skip to main content
replaced http://drupal.stackexchange.com/ with https://drupal.stackexchange.com/
Source Link

I have always put any fancy visibility logic inside the block view hook, eg,

$block['subject']='';
$block['content']='';

switch($delta) {

  case 'foo':

     if ( // visibility condition is true ) {
        // create the block['subject'] and block['content'] here
     }

     return $block;

}

since, if $block['content'] is empty, the block won't be displayed. This might be totally "against the drupal way," but I feel it makes for easier to read code and also takes one less php eval out of the loop.

ADDITION: This appears to get some approval here: Is there a way to set block visibility programmatically without using the PHP Filter module?Is there a way to set block visibility programmatically without using the PHP Filter module?

I have always put any fancy visibility logic inside the block view hook, eg,

$block['subject']='';
$block['content']='';

switch($delta) {

  case 'foo':

     if ( // visibility condition is true ) {
        // create the block['subject'] and block['content'] here
     }

     return $block;

}

since, if $block['content'] is empty, the block won't be displayed. This might be totally "against the drupal way," but I feel it makes for easier to read code and also takes one less php eval out of the loop.

ADDITION: This appears to get some approval here: Is there a way to set block visibility programmatically without using the PHP Filter module?

I have always put any fancy visibility logic inside the block view hook, eg,

$block['subject']='';
$block['content']='';

switch($delta) {

  case 'foo':

     if ( // visibility condition is true ) {
        // create the block['subject'] and block['content'] here
     }

     return $block;

}

since, if $block['content'] is empty, the block won't be displayed. This might be totally "against the drupal way," but I feel it makes for easier to read code and also takes one less php eval out of the loop.

ADDITION: This appears to get some approval here: Is there a way to set block visibility programmatically without using the PHP Filter module?

Source Link
Jimajamma
  • 17.1k
  • 1
  • 28
  • 35

I have always put any fancy visibility logic inside the block view hook, eg,

$block['subject']='';
$block['content']='';

switch($delta) {

  case 'foo':

     if ( // visibility condition is true ) {
        // create the block['subject'] and block['content'] here
     }

     return $block;

}

since, if $block['content'] is empty, the block won't be displayed. This might be totally "against the drupal way," but I feel it makes for easier to read code and also takes one less php eval out of the loop.

ADDITION: This appears to get some approval here: Is there a way to set block visibility programmatically without using the PHP Filter module?