Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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?
Comments
Comment #1
dawehnerThis seems to be like a valid behavior at the moment,
so what about a feature request to "pull title" from the subview.
Comment #2
BarisW CreditAttribution: BarisW commentedHi 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.
Comment #3
dawehnerI 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.
Comment #4
Deg CreditAttribution: Deg commented+1 Just ran into this issue today and would love better title management for no results views.
Comment #5
jacobroufa CreditAttribution: jacobroufa commentedAnother +1. I'll be looking into this tonight, for sure, and see what I can hack together.
Comment #6
dawehnerYou have to use $view->set_title('new title'); to override the title of the view.
Comment #7
kyleoliveira CreditAttribution: kyleoliveira commentedThis 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.
Comment #8
jpstrikesback CreditAttribution: jpstrikesback commentedHere'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...
Comment #10
jpstrikesback CreditAttribution: jpstrikesback commentedAnd again, with feeling
Comment #12
jpstrikesback CreditAttribution: jpstrikesback commentedShoulda read that test log a little closer.
Comment #13
jpstrikesback CreditAttribution: jpstrikesback commentedComment #14
jpstrikesback CreditAttribution: jpstrikesback commentedWowza, 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...
Comment #15
jpstrikesback CreditAttribution: jpstrikesback commentedAlso 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 inputComment #16
alexp999 CreditAttribution: alexp999 commentedConfirmed 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.
Comment #17
kclarkson CreditAttribution: kclarkson commentedI 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
Comment #18
jpstrikesback CreditAttribution: jpstrikesback commentedOoops, 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?
Comment #19
alexp999 CreditAttribution: alexp999 commentedAny 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.
Comment #20
PiroXXI CreditAttribution: PiroXXI commentedHi,
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.
Comment #21
Blanca.Esqueda CreditAttribution: Blanca.Esqueda as a volunteer and at Portage CyberTech commentedI 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.
Comment #22
Blanca.Esqueda CreditAttribution: Blanca.Esqueda as a volunteer and at Portage CyberTech commentedPlease review the follow patch.
Some changes has been done:
Comment #23
alexp999 CreditAttribution: alexp999 commentedThis needs re-doing since the following change in Views 7.x-3.12:
Make it easier to subclass views_handler_area_view
Comment #24
alexp999 CreditAttribution: alexp999 commentedI 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.