0

Using Drupal V 7.34 and Views 7.x.38

On the front page I have a view that lists news articles based on publish date being in the last 2 weeks. This works fine.

What I am now wanting is to insert a new view to pull images from Flickr when there are no news articles to show.

So, I created a new view for the Flickr feed, and adjusted the paging as I wanted. I set up the No Results Behaviour to show my new view in the Global View Area.

This works, but the title of the view is not displayed.

How can I show the title of the NRB view?

Many thanks

2 Answers 2

2

i believe this is your problem

https://www.drupal.org/node/1602058

solution is here

https://www.drupal.org/node/1176080

If you have a view and you want to be able to programmatically change the title of, you can do it by implementing hook_views_pre_render in your custom module: alter it when particular view or field is not having any result

<?php
function mymodule_views_pre_render(&$view) {
  if ($view->name == 'my_view_name' && $view->current_display == 'my_display_id') {
    // Here you can do any php you want to get the title you need for your view.
    $view->build_info['title'] = "My custom title!";
  }
}
?>

If you are altering the query and you have argument substitutions affecting the title, you can change these in hook_views_query_alter:

<?php
function mymodule_views_query_alter(&$view, &$query) {
  if ($view->name == 'my_view_name' && $view->current_display == 'my_display_id') {
      // First substitution - you may want !1 or %2, etc
      $view->build_info['substitutions']['%1'] = $new_substitution;
    }
}
?>

Views Displayed as Pages

Use this:

drupal_set_title('My custom title!');

Instead of:

$view->build_info['title'] = "My custom title!";

or some thing like this in views 3

<?php
/**
 * Implements hook_views_pre_view().
 */
function MODULENAME_views_pre_render($view) {
  if ($view->name == 'my_view_name') {
    if ($view->current_display == 'my_display_name') {
      $view->set_title('my new title');
    }
  }
}
?>
3
  • OK, thanks Deveraj.... Although this now extends past my knowledge of the php for Drupal, still.... I assume I can create a php function somewhere that will override the default Views one?
    – Darren
    Jan 16, 2015 at 16:28
  • yes you can override the default one by your custom title by adding some condition based on your requirement Jan 17, 2015 at 6:34
  • still you face issue in displaying the title for no result behavior. none of the above methods worked Darren Jan 20, 2015 at 17:30
0

There is a patch to Views here that will display the title from the View set in the No Results Behavior. Hopefully it will eventually be accepted into the module, but hasn't been reviewed for two years.

0

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.