I am creating a content type for listing general information about local public libraries. One of the things I want to include is a "Powered by Drupal" icon. If in fact they are. My desire is to have a yes/no field in the create content page that if checked 'yes' the logo appears and obviously if 'no' then it does not.

Of course I've tried searching for a solution, but I'm having trouble choosing search terms that return relevant information.

Any ideas will be GREATLY appreciated.

Thanks,

TBG

Comments

anthonylindsay’s picture

One possible solution would be to use a .tpl.php file for your content type and put logic in there.

So when your node loads it would test the value of your yes/no field and depending on the value of that, output the required image.
e.g. you could put this in a template file called node-mycontenttype.tpl.php, which would be basically a copy of node.tpl.php from your theme, or from your base theme, or core if it is not already in your theme.

You'll note from the docs on node.tpl.php that the template has access to the full node object, $node.

  // put this wherever in your layout you want the image to appear
  // test the value of your field
  // be careful to test for the machine value, not the displayed value, which may not be the same.
  if ($node->the_name_of_the_field_you_want_to_test[0]['value'] == 'yes' ) {
    // output your image html
    $image_output = '<img src = "path_to_images/image.jpg" alt="an image" class = "some_class" />';
    print $output;
  }
  
technobrarygeek’s picture

Thanks Anthony,

I tried your solution. It kind of worked. It displayed the image in the field location I wanted, but broke everything else. lol

I have contemplate enabled for another module. I've tried to edit the template there but when I do it jsut shows the php for each field not the 'results'.

It appears I need to do some learnin' on contemplate. But, you pointed me in the right direction.

Thank you.

TBG

anthonylindsay’s picture

Status: Active » Closed (fixed)

No problem.

Marking resolved.