Dan
Dan

Reputation: 1719

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

Upvotes: 0

Views: 2909

Answers (3)

Xacobe MA
Xacobe MA

Reputation: 1

This worked for me

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

Upvotes: -1

Greg
Greg

Reputation: 748

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

Upvotes: 0

Muhammad Reda
Muhammad Reda

Reputation: 27043

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)

Upvotes: 2

Related Questions