Drupal 7 custom embed view
I recently had a problem with views_embed_view function while embedding certain views in template file. In some cases a view might be empty, i.e., may not have any results.
In my case, I embedded some views in template file and had certain styles for the div that wrapped the view. These styles should be displayed only if the view was not empty. I checked if the view was empty or not, then only rendered the wrapping div along with the view in the template file. But what I witnessed was not what I expected. Though the view was empty, the styling was displayed along with the wrapping div. Later I found that views_embed_view function returns the following markup even when the view is empty.
<div class="view view-kf-content view-id-kf_content view-display-id-block view-dom-id-sd2db2bfcdh546hfddfba7ad95sdff32">
</div>
To overcome this problem, I came up with a custom function that will return the result (only if exists)