Reputation: 1719
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
Reputation: 1
This worked for me
<?php if ($content["field_hide_title"]["#items"][0]["value"] == 0) { ?>
<?php echo $node->title; ?></h2>
<?php } ?>
Upvotes: -1
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
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