Hello -

I'm working on a custom content template using the contemplate module and have run into a problem I've never had to tackle before. If you wouldn't mind spending a couple minutes helping me, please read on.

I've got a CCK field that has five options. The CCK field allows the user to check one or more options. Let's call it: Selections

Selections

  • Option A
  • Option B
  • Option C
  • Option D
  • Option E

What I'd like to do in my content template is display certain fields based on whether a certain option has been selected. I know how to show a field with contemplate based on whether the field has a value or not, but I don't know how to do it with various possible values.

So, let's say "Option A" has been selected, then I want to be able to determine that using PHP so I can output a certain field that should only be visible if Option A is selected. I have found the conditional template module and that seems to only control whether the fields are available in the node creation form, not in their actual display.

Thanks for your help. I'm really lost here!

Comments

nevets’s picture

If you want to conditionally print a value if it's set you would use something like

<?php if ( !empty($node->field_last_name[0]['view']) ) : ?>
<div class="field field-type-text field-field-last-name">
  <h3 class="field-label">Last Name</h3>
  <div class="field-items">
      <div class="field-item"><?php print $node->field_last_name[0]['view'] ?></div>
  </div>
</div>
<?php endif; ?>

To also limit passed on the value of another field you would change

<?php if ( !empty($node->field_last_name[0]['view']) ) : ?>

to something like

<?php if ( !empty($node->field_last_name[0]['view']) && $node->field_sections[0]['view'] == 'Option A' ) : ?>

'field_sections' needs to reflex the actual field name and 'Option A' the actual value you are checking for.

crbassett’s picture

Nevets, thank you so much. This is exactly what I needed.