Afternoon all,

I have a node of type X. This node has a list field and a field collection. I've created a node template for node type X and a field template for the field collection. From within the field collection template, I need to be able to check the value selected of the list field. Is there a way to pass this value from the node list field to the field template?

I thought that the best way to achieve this would be to use a field template specific preprocessor in template.php (mytheme_preprocess_field__field_collection()), but that function won't fire. I can set a variable in the generic 'field' preprocessor in my $vars array, but don't have access to the $variables array, where I've added the value for the list field.

Any help would be appreciated. Thank you for your time.

current template.php code:

function mytheme_preprocess_node__X(&$variables) {
    $node = $variables['node'];
    $node_wrapper = entity_metadata_wrapper('node', $node);
    if ($node_wrapper->field_collection_field->value()) {
        $variables['field_collection_field_value'] = $node_wrapper->field_collection_field->value();
    else {
        $variables['field_collection_field_value'] = 'not found';


function mytheme_preprocess_field(&$vars, $hook){
  $vars['field_collection_field_check'] = 'setting the variable manually';

Your Answer

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

Browse other questions tagged or ask your own question.