Is there a way to know the view type (page or block) from PHP code?

if (views type is block) {
  echo "This is a block view.";
elseif (views type is page) {
  echo "This is a page view.";

In the Views module, the exact term for what you're talking about is display handler.

If you have a view object, you can find the current object for the display handler at $view->display_handler. The class for that object is returned by get_class($view->display_handler), which would return a string like 'views_plugin_display_page', for example.

When checking the class of an object, you can use instanceof, as in the following code.

if ($view->display_handler instanceof views_plugin_display_page) {
  // Your code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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