I have PictureEvents and those have a few boolean fields:

HasCD | HasDVD | HasSlowMo

I'd like to have an icon for each of them that is dim/bright in all the places where it's shown (I have a few Field-Views for the lists of PicutureEvents, and I'd like to place the icons below the video in the main page).

Where do you do this in Drupal 7?


Easiest way to do this would be in a content-type template. You want to create a template for your content type, ex. node--[type|nodeid].tpl.php and add this in your theme folder. In your template, for displaying the boolean field you could use logic like this:

if ($node->field_boolean_field[$node->language][0]['safe_value'] == 0) { 
    print "<img src='no_img.jpg'>";
} else {
    print "<img src='yes_img.jpg'>";

This similar question may help as well:

Optionally add image/icon after node title based on boolean content type field?

  • I almost did it a different way, but it's giving me ugly html: ` In the HasDVD field, On Value = <img src="/icons/dvd-yes.png" alt="DVD available"> in the content-types->edit field area. ` That works, but it's putting the image into the field-- the View's output is like: <img alt="No CD" src="data:image/png;base64,iVBORw0 ..."> (ick!) Is there a way to "use what I gave it"? – Thor Apr 8 '12 at 17:52
  • Looks like its base-64 encoding your image to store it in the database. Where are you adding this code in? Is this in the content-type -> fields interface, or within the view itself? – schnippy Apr 9 '12 at 15:25
  • I put it in the content-type->fields interface. – Thor Apr 17 '12 at 1:48
  • where did you put this in the fields interface? Under field settings -> 'on value' / 'off value'? there is no option in the field settings interface for controlling output, only for controlling what goes in to the database which is probably why you are getting the base-64 response above.. if you want to control the display of the data, you need to do that at the theme level. have you tried adding a template for your content type? – schnippy Apr 18 '12 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.