Hi folks,

I have a view that display unformatted fields :
- a boolean field
- a date field
- a title field

I want to change the title class if boolean field is checke and a date field is lower than current datetime)

My problem is that I can't even make the test on the boolean field :

I first tried

<?php if ($fields["field_boolean"] == '1') :
echo "TRUE";
endif;
?>

No error, but the comparison is alwas false

So I tried

<?php if ($fields["field_boolean"] == 1) :
echo "TRUE";
endif;
?>

It says : "Object of class stdClass could not be converted to int in include()"

Then I tried

<?php 
  if (isset($content['field_boolean'][LANGUAGE_NONE][0]['value'])) :
    if ($content['field_boolean'][LANGUAGE_NONE][0]['value'] == 0) : 
      echo "TRUE"; 
    endif;
  endif; 
?>

The views is broken

Any idea ?

Comments

saurabh.dhariwal’s picture

You can get your field value with below code.

<?php
        print $fields['columnname']->content;
        // i.e. $fields["field_boolean"]->content;
        // your codition will look like.
        if($fields['columnname']->content == 'value for compare'){
                
        }        
?>

You can print your field columnname with below code.

<?php
        drupal_set_message('<pre>' . print_r(array_keys($fields), TRUE) . '</pre>');
?>

Hope this helps you.

Thanks!

renatog’s picture

Status: Active » Reviewed & tested by the community

Hi @thibaut51 how are you?

#1 is an solution for your case.

You can make the condition and print your value using print_r, drupal_set_message, and others.

RTBC

renatog’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @saurabh.dhariwal

@thibaut51; Any question, please comment for us.

Thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.