1

I have found a solution in "Hide a view if less than N results" for hiding the view by using the template.php file.

However I need to show a certain block also, the block is already in the correct region it would just need 'switching on' for this page.

Would it be possible to provide a callback inside the following code from the link posted above

function MY_THEME_NAME_preprocess_views_view(&$vars) {
  if ($vars['display_id'] == 'MY_DISPLAY_ID' && count($vars['view']->result) < 1) {
    $vars['view']->result = NULL;
  }
}

To a function which turned the block on

Note: I am just starting module development.

edit: I'm now thinking that this would need to be done inside a custom module as it might be too late to turn the block on from the template.php file. If someone could clarify this.

| improve this question | | | | |
  • Is the block that you're talking about a view block or a regular/normal block? – No Sssweat Oct 25 '16 at 8:25
  • yes it is a views block.. ahh I think I see where this is going, nice thinking – user43161 Oct 25 '16 at 8:29
0

Part 1

Enable the Rules block visibility module. Here is a quote from its project page:

The Rules block visibility module allows Rules components to be used to control block visibility. This provides Drupal administrators and developers extreme flexibility in controlling when blocks should be displayed on their websites, in addition to the default visibility options provided by Drupal.

The general idea is that if you can do it with Rules, you can use it to control block visibility, so the possibilities are limitless:

  • Need to show a block only for users registered more than a month ago?

  • Perhaps you have a block that must be shown only between 8am-5pm on weekdays?

  • What about displaying or hiding a block based on current weather conditions?

All of this can be done by using Rules block visibility.

For an illustration of how to use this module, refer to my answer to "How to stop a Views block from displaying to admins, such as user/1?".

Part 2

As per the "if you can do it with Rules, you can use it to control block visibility" above, you've reduced your question to making Rules "check the number of rows returned by your view" (so that the block is only shown if the view has more then 1 row).

For that, perform these steps:

  1. Use the Views Bulk Operations module to create a variation of your view in which you add a VBO field to it.
  2. Create a Rules Component with a Rules condition "Check number of results returned by a VBO view". And select the VBO view created in the previous step.
| improve this answer | | | | |

Your Answer

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