Some additions to the answer from Taggart Jensen ...
I agree with using hook_node_view.
You have a few ways of going about this.
- Using the Hook in the template.php file of your custom theme.
- Making a small custom module and using the hook in there.
I would recommend the second option so that this is not theme-dependent.
Let's say you want to name your module foo_display.
- Create the folder sites/all/modules/foo_display
- Create sites/all/modules/foo_display/foo_display.info file (Note: Read here for more details on making an info file.) For the sake of this example, feel free to use this:
name = Foo Display
description = Changes how field_foo and field_bar are displayed based on their values.
core = 7.x
- Create sites/all/modules/foo_display/foo_display.module file.
- Enable the foo_display module you created.
Inside of the foo_display.module file, we are going to use hook_node_view().
Start with the following code:
<?php
foo_display_node_view($node, $view_mode) {
if ($node->type == 'MACHINE_NAME_OF_CONTENT_TYPE') {
// Logic for Fields Here
return $node;
}
}
It was right of you to see that putting logic in the theme is not the right place. Doing something like this is a bit more Drupal-y.
I also saw that you were having trouble getting field-specific data.
I recommend using Entity metadata wrappers.
Here is an example of how you could use it in your scenario:
<?php
foo_display_node_view($node, $view_mode) {
if ($node->type == 'MACHINE_NAME_OF_CONTENT_TYPE') {
// Create Entity Metadata Wrapper for the Node being viewed
$node_wrapper = entity_metadata_wrapper('node', $node);
// Get the Value of field_foo
$field_foo_value = $node_wrapper->field_foo->value();
// Get the Value of field_bar
$field_bar_value = $node_wrapper->field_bar->value();
// Check if field_bar has a value or not
if ($field_bar_value == NULL) {
// Render both values together
}
return $node;
}
}
I hope that this helps to get you started!