4

What is the snippet of code to make a block just show in pages generated by a certain View?

enter image description here

Using Drupal 6 with Views 2.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Naoise Golden
  • 8,793
  • 4
  • 49
  • 65
  • Can you not just put the paths of the View pages into the "Show on only the listed pages" box? Or do you need something dynamic? – Graham May 10 '11 at 16:09
  • Thing is the path is both for views and nodes: `/foo/list` is View, `/foo/list/node` is node. – Naoise Golden May 10 '11 at 16:27

2 Answers2

2

You can use views_get_page_view() to retrieve the view currently in use.

<?php
  $display = views_get_page_view();
  $view = $display->view;
  return !empty($view) && $view->name == 'Foo';
?>
Naoise Golden
  • 8,793
  • 4
  • 49
  • 65
Pierre Buyle
  • 4,883
  • 2
  • 32
  • 31
1

On Drupal 7 this works:

<?php
  $view = views_get_page_view();
  return isset($view) && $view->name == 'Foo';
?>
JLRishe
  • 99,490
  • 19
  • 131
  • 169
geraldo
  • 562
  • 11
  • 33