1

I have the $is_portfolio variable in my "template.php" file that lets me easily check what content type is being displayed, so I can do freaky and awesome stuff with it:

function mycooltheme_preprocess(&$variables, $hook) {
  if ($hook == 'page' ) {
    if ($variables['node']->type == 'portfolio') {
      $variables['is_portfolio'] = TRUE;
    }
    else {
      $variables['is_portfolio'] = FALSE;
    }       
  }
}

In my "page.tpl.php" file, I use it through a conditional which lets me change the markup depending on the content type:

<?php if ($is_portfolio) : ?>
  // Use this layout
<?php elseif (!$is_portfolio) : ?>
  // Boo, use this layout instead :-(
<?php endif; ?>

How can my code in "template.php" be customized so it can also check which Views page is being displayed, so I can target those as well?

2 Answers 2

2

Use menu_get_item() to retrieve the page callback for the currently shown path, and check it correponds to 'views_page', which means you are in a view.

function mycooltheme_preprocess_page(&$vars) {
  $menu_item = menu_get_item($_GET['q']);

  if ($menu_item['page_callback'] == 'views_page') {
    $vars['is_portfolio'] = ($menu_item['page_arguments'][0] == 'path_of_your_view');
  }
}

You can also use current_path() directly, but I found interesting to know that you're on a Views page using menu_get_item().

1
  • Thanks for this man. I'll try it out and get back to you.
    – enchance
    Aug 1, 2011 at 5:45
1

Alternative you can use

$view = views_get_page_view();
$name = $view->name;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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