If you create a block view and define another view to be used when the first view has no results, the title of the first block is still displayed above the block - even if the second view has a different title.

I tried changing the render() function in views_handler_area_view.inc to do a set_title(), but this doesn't seem to work. Any ideas?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Title: No results behavior - View Area does not inherit titles for blocks » No results behavior - Allow View Area to push title to main view.
Category: bug » feature

This seems to be like a valid behavior at the moment,
so what about a feature request to "pull title" from the subview.

BarisW’s picture

Hi Daniel,

thanks. Just wondering: when is an issue a bug and when is it a feature request? When you can define a title, but it isn't used, isn't it just a bug? If it was meant to be this way; shouldn't there be a message that it works this way? It took me quite a while to figure out the problem.

dawehner’s picture

I think there is no easy way to define a 100% definition what is what, especially in this case, it seems to be that the title from the min view wasn't expected to be pulled from the subview, so adding a feature is better then fixing a bug, but that's my perspective.

In general i prefer to add features instead of changing current behavior, you newer know whether people might rely on that.

Deg’s picture

+1 Just ran into this issue today and would love better title management for no results views.

jacobroufa’s picture

Another +1. I'll be looking into this tonight, for sure, and see what I can hack together.

dawehner’s picture

You have to use $view->set_title('new title'); to override the title of the view.

kyleoliveira’s picture

This would be much appreciated. So far I've been working around it with a kludgy combination of block Views for the true content and different page Views (chained together by no results behavior) to handle the titles.

jpstrikesback’s picture

Status: Active » Needs review
FileSize
3.91 KB

Here's a patch that does this but I want to see it pass tests. The way it brings in the titles is maybe messy, and the way it does token replacement(by building another view side by side) is kinda ugly.

Any ideas on how to do this better are welcome. I'd like to see if I can get the tokens & substitutions passed thru, but that may be a luxury I can't afford...

Status: Needs review » Needs work

The last submitted patch, global-views-area-titles-and-tokens.patch, failed testing.

jpstrikesback’s picture

Status: Needs work » Needs review
FileSize
3.9 KB

And again, with feeling

Status: Needs review » Needs work

The last submitted patch, 1388332-global-views-area-titles-and-tokens-10.patch, failed testing.

jpstrikesback’s picture

Shoulda read that test log a little closer.

jpstrikesback’s picture

Status: Needs work » Needs review
jpstrikesback’s picture

Wowza, so far so good.

The fact that the inherit_title & inherit_first_for_tokens depend on arguments being present may be something to change but it would probably kill something somewhere so I left it as only for usage when arguments are passed from the parent to the child...

jpstrikesback’s picture

Also maybe a && !empty($this->view->args) should be in the $views_copy creation condition to save on building a second object in memory, then again, maybe this is so flipping bad that none of that matters, so I'll leave it 'til there is further input

alexp999’s picture

Confirmed working on 7.x-3.5.

Works absolutely perfectly, I searched for a solution and came across this patch.

I have an e-commerce site that basically shows a view with the subcategories if no products are found, this enables the title of the subcategory view to come through when no results are found.

Before the patch I was left with an uncoverted token, when no results were found, which I couldn't override.

kclarkson’s picture

I just came across this today.

My use case is that I am using views + views panel fields, to create user tabs of content.

For example: I would like the user profile to have user tabs for user generated content. If a user does not have any content, my token titles show [field-firstname] [field-lastname] Generated content.

@jpstrikesback
-The patch had a couple of whitespace errors but it still applied. Unfortunately I am still seeing the token fields instead of the values. Not sure if there was something that I needed to do for views to see this patch has been applied. I cleared the cache and resaved my view. Any help would be much appreciated.

I am using Views 7.x-3.5+24-dev

jpstrikesback’s picture

Ooops, made that before I started using Dreditor. I actually made it into a separate module so I could use it and update views :) I'll upload a sandbox late tonight or tomorrow, If I forget please feel free to remind me :)

Regarding the token names showing up, if there are no results they will show up as raw text (like [title]'s posts) If I recall correctly (as they come from the first row) Any ideas for a fallback?

alexp999’s picture

Any chance of getting this committed or the module out (at least in dev on drupal?).

As a fallback, could we simply, just not modify the title, and use the parents default title? i.e. only override title from no results view if a token actually exists.

Cheers.

PiroXXI’s picture

Issue summary: View changes

Hi,

It seems that the proposed patch doesn't work well with the module viewreference. I'm getting the following error :
Notice: Undefined index: in theme_viewreference_display_title() (line 704 of /sites/all/modules/viewreference/viewreference.module).
Notice: Trying to get property of non-object in theme_viewreference_display_title() (line 704 of /sites/all/modules/viewreference/viewreference.module).

I would have appreciated this feature. The current behavior is quite problematic as I couldn't find any way to modify the View's title when the view is empty.

Blanca.Esqueda’s picture

Status: Needs review » Needs work

I tried the patch and it worked partially. I was getting similar notices as @PiroXXI and I wasn't using the viewreference module, but those notices appear when the token replacements option is checked.

Blanca.Esqueda’s picture

Status: Needs work » Needs review
FileSize
2.85 KB

Please review the follow patch.

Some changes has been done:

  • Inherit title doesn't depend on arguments being passed anymore. the inherit title would work even if Inherit contextual filters option is not checked.
  • Inherit title with first row token replacements option has been removed as it wasn't needed anymore. The option inherit title has been updated so it passes the title with or without tokens replacements.
  • Inherit title strip tags option has been added. Tokens replacements could contain tags, so strip tags is useful in cases where the title is displayed only in plain text (As panel pane).
alexp999’s picture

Status: Needs review » Needs work

This needs re-doing since the following change in Views 7.x-3.12:

Make it easier to subclass views_handler_area_view

alexp999’s picture

I still haven't got my head around making patches, but here is my modified views_handler_area_view.inc file based on Views 3.13 and the patch from #22.

Seems to be working as expected.