Sign up ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I've create a view which displays all nodes with content type location. This view renders the node using it's teaser display, which I've created a custom node--location--teaser.tpl.php for.

In this template, I'm using entity_metadata_wrapper as a cleaner way to theme values. My template begins with;

<?php 
  $nw = entity_metadata_wrapper('node', $node);
  dpm($nw->value());

  $name     = $nw->label();
  $phone    = $nw->field_phone->value();
  $fax      = $nw->field_fax->value();
  $address  = $nw->field_address_plaintext->value();
?>

All of the stored variables used for themeing return values for the first node rendered by the view, but subsequent nodes only return a value for the $name variable.

If I remove dpm($nw->value()); from line 3, I receive the appropriate values for all view results.

What is happening here? Why does dpm() cause this to happen?

Update

I've moved this logic to a node preprocess function based on feedback from @Clive:

function _preprocess_location(&$vars) {
  $nw = entity_metadata_wrapper('node', $vars['node']);

  $vars['nw']['name']       = $nw->label();
  $vars['nw']['image_url']  = file_create_url(image_style_path( 'location_thumbnail', $nw->field_image->value()['uri']));
  $vars['nw']['phone']      = $nw->field_phone->value();
  $vars['nw']['fax']        = $nw->field_fax->value();
  $vars['nw']['address']    = $nw->field_address_plaintext->value();
}

If I add a dpm() call anywhere in this function I encounter the same problem as described above.

share|improve this question
    
I can't quite put my finger on what's causing this, but having that code in a template file isn't a good idea (templates are evald, something in that might be causing the issue) - try moving the logic out to a preprocess function and see if you get the same results –  Clive Aug 26 at 18:25
    
Thanks @Clive — I agree that logic should be separate from presentation. Typically I move this all over once I'm out of my messy 'design' mentality. Unfortunately, it didn't fix the issue (see update). –  Aaron Silber Aug 27 at 13:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.