0

Drupal 7. I'm trying to display a block using the "Pages on which this PHP code returns TRUE" feature. The field is a single value list (text) named field_display_block so all I want to do is determine if field_display_block is set to "1".

I'm sure there are a couple of ways to do this. Any help on this would be greatly appreciated.

Thanks

Les Z

1 Answer 1

3

With the following script you can check the value and return true. I've added my comments before each line.

// First check if the current page is a node
if ($node = menu_get_object()) {
 // Then, check if it is your content type
 if ($node->type == 'your_content_type') {
   // Get the value of your field
   $display_block = field_get_items('node', $node, 'field_display_block');
   // If the field's value is equal to 1, then return true
   if ($display_block[0]['value'] == '1') {
     return TRUE;
   }
  }
}
0

Your Answer

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

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