0

I'm trying to write a statment that looks at the value in a boolean field (field_solo) and returns one of two template files that I have created in Drupal 7.

My field "field_solo" is correctly outputting a value of 0 or 1 and I have cleared the cache.

Can someone tell me if I am doing this correctly? Right now I am not getting it to display when the statement is TRUE.

function motg_preprocess_node(&$vars) {

$node = $vars['node'];
  if($node->field_solo[0]['value'] == 1)
  {
       $vars['theme_hook_suggestion'] = 'node__solo';
  } else
  {
       $vars['theme_hook_suggestion'] = 'node__video';
  }
}
Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
Dan
  • 1,709
  • 5
  • 15
  • 21

3 Answers3

2

Instead of

if($node->field_solo[0]['value'] == 1)

Make it

if($node->field_solo['und'][0]['value'] == 1)
// OR
if($node->field_solo[LANGUAGE_NONE][0]['value'] == 1)
Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
0

Have a look at this it could be helpful: http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way

Greg
  • 748
  • 8
  • 19
-1

This worked for me

<?php if ($content["field_hide_title"]["#items"][0]["value"] == 0) { ?>
<?php echo $node->title; ?></h2>
<?php } ?>