0

I've added a series of blocks to my template file for a specific content type. These blocks are built in Views and they show Downloads filtered by the specific content you are viewing. For example, on the Product A page, the Product Literature block shows all downloads categorised as Product Literature specifically associated with Product A.

There is a block for Product Literature, a block for Videos (set up in a similar way) and a block for Publications (again, set up in a similar way).

At the moment, if there aren't any videos for Product X, the heading Product X still displays for Video Gallery, is there a way I can detect if there is any content under the Video Gallery heading and if there isn't, choose not to display it?

Each block is printed as below:

$block = module_invoke('views', 'block_view', '712046d635e195e59dd93bd378e45423');
print "<h2>Product Literature</h2>";
print render($block);
2

If you create blocks from the views interface itself it will not print the block if there are no results. I would recommend this method since it saves time and complexity. If you need to change the template for the block being created by the view you can do so. There is a lot of documentation on how to do that. Here is an example: Create template file for views block

In the case of what you have written below you could do something like:

$block = module_invoke('views', 'block_view', '712046d635e195e59dd93bd378e45423');
if (isset($block)) {
print "<h2>Product Literature</h2>";
print render($block);
}

but I would highly recommend the approach above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.