With the devel module enabled, I printed out the row id to the messages and also to the screen in a field template:

dpm($id);
print $id;

In a view displaying 10 rows, this results in 1-20 showing up in the messages area, and 11-20 showing up on the page.

The line that is re-rendering the row is line 26 in semanticviews.module.

Is there a way for this not to happen? I needed to handle the first item differently, and I'm not able to do that now when using this module.

Comments

Anonymous’s picture

When you call dpm() in the template, the page template's messages variable has likely already been generated by the time dpm($id) is called. dpm() stores its output in the user's session by calling drupal_set_message. The output of the dpm() function calls is not seen until the next page request.

To test this, start on the first page of your view. You'll see only the printed $id in the page. Page forward. You'll see the second page of $ids printed but the first page's $ids in the message area of the page. Then navigate to a page where your view is not displayed (maybe /admin ?) and you will see the second page's $ids in the message area of the page.

If this is the problem, you need to put the dpm($id) function somewhere outside the template. There are views hooks that can peek in on the id, but I can't advise you on that. The best resource is http://views.doc.logrus.com/ where the Views 2 hooks are documented. I suspect if you try with the preprocess function for the semantic views template, you will see the same result that brought you here, but it could be worth a shot. (I can't test it meself.)

Mark the issue "fixed" when you're done unless you determine that this isn't the problem you're having.

Anonymous’s picture

Silly me. The most obvious solution is to use HTML comments in the template to print the information. dpm() is just not a suitable option for debugging templates like this.

karlshea’s picture

I read up a bit more on this, and I don't think the line I referenced is the issue.

But the base issue here hasn't changed... the fields are getting rendered twice.

Here's a field template I'm using that shows the behavior:

<?php
global $is_first;

if(isset($is_first)){
    $is_first = FALSE;
}
else {
    $is_first = TRUE;
}
?>
<?php if($is_first): ?>
    <!-- This is the first item: <?php print $id ?> -->
    <?php print $output ?>
<?php else: ?>
    <!-- Not the first: <?php print $id ?> -->
<?php endif; ?>

The first comment never prints, and rows shown all print 11-20. But if I'm using dpm($id), I get 20 prints, from 1-20, so the template is being called 20 times. And if I comment out that line of code I referenced, I still get the 1-10 prints from dpm($id) even when there's nothing else on the page.

If I turn off semantic views and just use the Unformatted/Fields style, everything works fine, I only get 10 messages from 1-10.

This really wouldn't matter, except I need to output some things in the first item differently.

karlshea’s picture

Status: Active » Needs review

Hey I fixed it!

It was that line. In semanticviews.module, change line 26 from

$field_output = $view->field[$id]->theme($variables['row']);

to

$field_output = $view->style_plugin->get_field($view->row_index, $id);

and everything works fine!

I found the correct line in the views module in theme/theme.inc on line 170.

Anonymous’s picture

Thanks Karl. I think you're onto something here. I can't test it, but I am looking at it tonight.

Anonymous’s picture

Status: Needs review » Fixed

Committed. See commit message for background on the change in Views 2.

Commit #323932 by bangpound at 16:36

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.