简体   繁体   中英

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

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)

This worked for me

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM