Search code examples
phpdrupalif-statementdrupal-7drupal-theming

If/then statement on field value in drupal 7


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';
  }
}

Solution

  • 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)