How to prevent a View from rendering via a hook? I want to prevent an attached view from running depending on some coding parameters.

I've tried using hook_views_pre_view() to prevent it from running, but I can't figure out what options to set on the view to accomplish that. Tweaking attached or rendered doesn't seem to do anything.

function ding_eresource_views_pre_view(&amp;$view, &amp;$display_id, &amp;$args) {
  if ($view-&gt;name == 'eresource_list' &amp;&amp; $display_id == 'attachment_1') {
    // Prevent rendering if parent view has some option set.
    if (!empty($view-&gt;old_view[1]-&gt;barr)) {
      // This does not work. How can it be done?
      $view-&gt;attached = FALSE;
      $view-&gt;rendered = TRUE;
    }
  }
}


How can it be done?
Wanted to do similar but just $view-&gt;executed = TRUE; made the query in the view still run. Looking at view::build(), I understood you need the following code, to prevent anything running further in the view (displays and query).

$view-&gt;executed = TRUE;
$view-&gt;built = TRUE;


To make it clearer, the code you should use is the following one.

function ding_eresource_views_pre_view(&amp;$view, &amp;$display_id, &amp;$args) {
  if ($view-&gt;name == 'eresource_list' &amp;&amp; $display_id == 'attachment_1') {
    // Prevent rendering if parent view has some option set.
    if (!empty($view-&gt;old_view[1]-&gt;barr)) {
      // This does not work. How can it be done?
      $view-&gt;executed = TRUE;
      $view-&gt;built = TRUE;
    }
  }
}