I have a view that is being rendered, via a block, that is a summary/tally of records. It has a different output according to whether in Preview mode of Views, or live.

Live:

Preview:

The contextual filter returns the TID.

Block rendering code:

<?php

/**

* @file

* Template for outputting the default block styling within a Layout.

*

* Variables available:

* - $classes: Array of classes that should be displayed on the block's wrapper.

* - $title: The title of the block.

* - $title_prefix/$title_suffix: A prefix and suffix for the title tag. This

* is important to print out as administrative links to edit this block are

* printed in these variables.

* - $content: The actual content of the block.

*/

function gettid(){

global $user;


$tax= taxonomy_get_tree('vhb_team',0,3,true);


foreach($tax as $k=>$v){

if(isset($v->field_userid['und']) && isset($v->field_userid['und'][0])){


if(isset($v->field_userid['und'][0]['uid']) && $v->field_userid['und'][0]['uid'] == $user->uid){

if(isset($v->tid)){

return (int)$v->tid;

} else {

return false;

}

}

}

}

}

?>

<div class="block block-block-vhbtop4a">

<?php print render($title_prefix); ?>

<?php if ($title): ?>

<h2 class="block-title"><?php print $title; ?></h2>


<?php endif; ?>

<?php print render($title_suffix); ?>

<?php

if(gettid()){print"TID=".gettid();}

$rend=views_embed_view('roles','openingsblock_tally');

//$rend2=views_embed_view('organisations_exportable','archived_orgs_block');

// views_embed_view

//The first option is the machine name of the view, this is found if you hover over the edit link on the views page and look at the link address. The second is the block or page machine name, so if its the first block it would be block_1 or block_2. This is found in the view under the "Other" list.

if(!empty($rend2) || !empty($rend)){

print render($rend);

}

?>

</div>

There are in fact 39 records that shows the Preview to be correct. Why is the live block rendering wrong?

Accepted answer

Ok, so I found the source of the issue, and it is the draft content from one of the other threads; the team member cannot get the draft content within views, the admin can.

I will continue in that thread, as I have an idea of how to diagnose this...

 

Most helpful answers

My only idea at this point is that the view is not getting the tid correctly when you do it in the block. Can you try to hard-code "148" in the block code as the third argument of views_embed_view?

(As a sidenote, you don't need "print render()" because views_embed_view returns actual HTML markup already. Just "print views_embed_view()" will work).    

And if you try this in Devel's Execute PHP what do you get?

views_embed_view('roles','openingsblock_tally', 148);

 

You are not passing the tid to the view.

This function 

views_embed_view('roles','openingsblock_tally');

Should probably be:

views_embed_view('roles','openingsblock_tally', gettid());

Comments

You are not passing the tid to the view.

This function 

views_embed_view('roles','openingsblock_tally');

Should probably be:

views_embed_view('roles','openingsblock_tally', gettid());

Yeh, I am through the PHP inside contextual filter of the view, but for gigs I just tried the method you suggested and get the same result; 37. Hmmm.

And if you try this in Devel's Execute PHP what do you get?

views_embed_view('roles','openingsblock_tally', 148);

 

from

print render(views_embed_view('roles','openingsblock_tally', 148));

so I'm getting correct tally in Views, and in Devel, but not rendering, as if there is another function modifying at the template level?

My only idea at this point is that the view is not getting the tid correctly when you do it in the block. Can you try to hard-code "148" in the block code as the third argument of views_embed_view?

(As a sidenote, you don't need "print render()" because views_embed_view returns actual HTML markup already. Just "print views_embed_view()" will work).    

$rend=views_embed_view('roles','openingsblock_tally', 148); 

In the block TPL still results in 37.

And thanks, yes merely print works too.

I am trawling my template.php and custom module, but nothing has been built to modify Views results. Baffling.

I added another Opening to this team member (tid 148) and it incremented by 1 as expected, so now 38. (To be clear, the actual total is now 40)

Ok, so I found the source of the issue, and it is the draft content from one of the other threads; the team member cannot get the draft content within views, the admin can.

I will continue in that thread, as I have an idea of how to diagnose this...