global $current_view; 
print $current_view; 

the above code does not work for me. i have tested it with all the template files (node.tpl, page.tpl, etc.) i am using drupal 6.12 and views 6.x-2.5, has something changed drastically here? it used to work with previous versions of drupal, though. i want to create custom template files based on view. (specifically, page/block as per view name.)

Comments

dawehner’s picture

Priority: Critical » Normal

this was in drupal5

you should use now

<?php
$view = views_get_current_view();
?>

but just print $view will not work

mesh’s picture

thanks dereine,

it returns a views object. how do i extract the display being used currently? (page, block etc?)

mesh’s picture

dereine,

$view->current_display does it, right? but again, it gives me names like page_1, block_1 etc. instead of the display name itself.. any suggestion?

merlinofchaos’s picture

Status: Active » Fixed

$view->display[] contains the entire displays by key. $view->display_handler contains the object controlling the display.

mesh’s picture

thank you merlinofchaos,
but you confused me further. yes, the display handler contains the object controlling the display. upon print_r it shows a complete list of all displays for that view. i want to find out which display of all those (page, block etc) is deployed currently. this will help switching the template code accordingly. this is what i figured out -

$view = views_get_current_view(); 
$current_view_name = $view->name; 

returns name of the current view and,

$view = views_get_current_view(); 
$current_view_display = $view->current_display; 

returns the display being used.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

knalstaaf’s picture

In order to see the actual name you have to add the print-rule (if that's your question):

<?php
	$view = views_get_current_view();
	$current_view_name = $view->name;
	
	print $current_view_name;
?>

It only works when it's being used in the Views template-file.