I am using extensively the views_embed_view function in TPL, then handling logic in the TPL, for a dashboard scenario. It works really well, until I get to this one simple-looking view that refuses to work the way all the rest do, and I am banging my noggin trying to figure out why! I will post the code below if the system here lets me...

Accepted answer

Two more questions:

1. Do you see any results when you go to the view > your block, and click Update preview without providing a default value?

2. The "return 0;" above looks weird. What's the intended behavior? Show all when the entity reference field field_organisation is not present? If so, instead, have you tried returning the string "all"? Views have an "Exception" dropdown on the right side (see below) where the string "all" functions as a way to tell the view to show all results (in case this is what you want to do!). 

Comments

$rend=views_embed_view('applications','my_org_tally');

dpm($rend);

 

if(!empty($rend)){

print render($rend);

print '<hr>';

} else{

print'There are <span class="vhbred">0 new APPLICATIONS</span>. <br>';

}

 

Isn't it easier to create a block within your View, and place it in the dashboard using the layout UI? 

So, the problem only shows up when you use views_embed_view with this particular view? And what exactly is the problem? An empty view? 

Have you tried doing dpm of the html output within the Execute PHP UI provided by Devel? If so, does the view actually generate output?

Also, does this view use any contextual filter?

Lots of questions... :) 

Thanks mate:)

The block is created in the view, but rendered in the template because of the extra logic required that Views can't do. The layout ui is used to position the basic block, the tpl then fills it out.

The view is supposed to render a summary (using the global header) if there are actual results, and when there aren't, then do the usual 'no results' output of nothing, so that the TPL sees php empty as true, and spits a different message. (There's more to come than what I have there currently!)

The dpm is in the screenshot.

Yes, contextual filter applies. That part is working using Provide default Value, PHP;

global $user;
$account= user_load($user->uid);
if(isset($account->field_organisation['und'][0]['target_id'])){
return $account->field_organisation['und'][0]['target_id'];
} else {
return 0;
}

Two more questions:

1. Do you see any results when you go to the view > your block, and click Update preview without providing a default value?

2. The "return 0;" above looks weird. What's the intended behavior? Show all when the entity reference field field_organisation is not present? If so, instead, have you tried returning the string "all"? Views have an "Exception" dropdown on the right side (see below) where the string "all" functions as a way to tell the view to show all results (in case this is what you want to do!). 

1. No results visible. However I am sure that even if there is no result, Views is still actually returning html output now that it didn't earlier, so it must be something that I am doing. I have had to resort to workaround with the No Results area.

2. Yeh, tried return false, and simply ignoring as well. The zero was an attempt to pass an integer that was known. The contextual Filters actually had no effect on this process in the end as far as the No Results handling in the TPl are concerned.

Thanks for your help!