How do I check if the page I'm viewing is a Views page? I want the breadcrumbs to be hidden if the user is viewing the view page I made, which I named "Products."
I am using Drupal 7 and Views 7.x-3.0-beta3.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityHow do I check if the page I'm viewing is a Views page? I want the breadcrumbs to be hidden if the user is viewing the view page I made, which I named "Products."
I am using Drupal 7 and Views 7.x-3.0-beta3.
Following Jeremy French reply, I must say that you can do it like this :
if(function_exists('views_get_page_view') && views_get_page_view()){...YOUR CODE HERE...}
Taken from here:
views_get_page_view() finds out what, if any, page view is currently in use. If it returns NULL, then the current page is not a views' page.
Quick and dirty would be to use CSS - take the class Drupal assigns to the views page and then do something like:
.drupal-views-page-class .breadcrumb-container {display:none}
Of course, you need to use your actual class names.
For d6 site the following trick might work.
/** * Implementation of hook_views_pre_render() */ function mymodule_views_pre_render($view) { if ($view->name === 'my_products_view') { drupal_set_breadcrumb(); } }
<?php if(condition) : ?> This gets printed <?php endif; ?>
? That way I can just check if it's a Views page and not print the breadcrumbs.
– enchance
Jun 26 '11 at 13:31
<?php if(isset($view->name)) : ?>This gets printed<?php endif; ?>
works for you.
– leymannx
Jul 29 '14 at 14:30
I have some code that shouldn't be displayed on certain content types. There's an easy approach for this:
<?php if (!empty($node) && (($node->type != 'article') && ($node->type != 'webform'))): ?>
This content is shown everywhere except on articles and webforms. Yet it doesn't show up on views pages either while it should.
<?php endif; ?>
But it occured to me that it would hide this content for views pages as well (because the node is empty there: (!empty($node)
).
My workaround for this is:
<?php
if(function_exists('views_get_page_view') && views_get_page_view()){
$viewspage = "yes";
}
?>
<?php if (((!empty($node)) || (!empty($viewspage))) && (($node->type != 'article') && ($node->type != 'webform'))): ?>
This content is shown everywhere except on articles and webforms. It does show up on the other content types ànd the views pages. So it's ok.
<?php endif; ?>
This is working, but I wondered if this is the right approach. It looks a bit like a kindergarten-method.
For me the following works in hook_preprocess_page()
and in hook_preprocess_html()
as well:
function MYMODULE_preprocess_page(&$vars) {
$view = (array)views_get_page_view();
if (!empty($view)) {
// do stuff
}
}