Closed (fixed)
Project:
Views (for Drupal 7)
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Anonymous (not verified)
Created:
5 Sep 2011 at 03:27 UTC
Updated:
12 Feb 2020 at 11:37 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
merlinofchaos commentedAttachments don't actually display titles normally. For most views, the title is rendered completely separately. For attachments, because of this, they end up losing the title. You can work around this by using the header area text and placing the title token. It's a bit of a hack but it'll get you what you want without too much trouble.
Comment #2
Anonymous (not verified) commentedSweet. Much obliged. The current attachment display, however, is pretty confusing since one would assume that it would work exactly the same as a page or block. I'm reopening this as a feature request for opinion on whether it makes sense to change this so that people like me aren't confused. Either the title field should do something or it should be removed in the display configuration.
Comment #3
Anonymous (not verified) commentedAnd, by the way, the header option doesn't work. When I use it, it shows the View title, not the attachment display title. I think I'm going to open a bug on how lacking the API documentation is. Apparently there's a $view object that may solve all of my problems. I don't know because I can't find a word about what its properties or methods are. < frustration >I guess everyone's just expected to be born with knowing exactly what $view is and how it's used< /frustration >.
Comment #4
dawehnerDid you tryed to use the title token in the header of the attachment display?
Comment #5
Anonymous (not verified) commentedThese are my available replacement patterns when I select Header -> Global: Text Area:
Am I supposed to have the token module installed or something?
Comment #6
merlinofchaos commentedAh. Yes. There's no token for the title. So not much of a workaround. :/
Comment #7
Anonymous (not verified) commentedWhat's the most efficient way to get the attachment title using the API? I can plug it into the template. I can't use a static string because I have several attachments with different titles so I want it established programmatically.
Comment #8
merlinofchaos commentedFrom the template,
$view->get_title()should be all you need.Comment #9
Anonymous (not verified) commentedUnfortunately, no.
$view->get_title()gives me the taxonomy term, not the attachment display's title which I set.Comment #10
merlinofchaos commentedDoes your argument have a title that overrides the regular title?
Comment #11
Anonymous (not verified) commentedYes, the attachment display title overrides the page display title (which is empty) and the global title for the view (which may be the same as the page display title, I'm not sure how it works between D6 and D7).
Comment #12
fietserwin#304969: Show title for attachment displays is a duplicate but for 6.x-3.x
Comment #13
moonray commentedRunning into the same problem. Will the patch for D6 (modified to work with D7 version) work? Is it a good solution?
Comment #14
patoshi commentedsame issue too. have a page display and made an attachment and the total view doesnt show any title
Comment #15
sorensong commentedi love drupal support.
Comment #16
rooby commented@sorensong:
Compared to what? Do you use other things for free that have first class support for anyone who wants to use them in any way? Including the addition of new features?
Comment #17
rooby commentedThe patch in #304969-35: Show title for attachment displays may still be relevant for drupal 7.
It think there is definitely a decent use case for adding this feature.
Comment #18
monish_deb commentedI have been able to show the Attachment title by using $view as available variable for "Header -> Global: PHP". This is the Output code:
I am not sure whether it is a correct approach but for now it served my purpose.
Comment #19
rooby commented@monish_deb:
You can also use filtered HTML and just enter the title text instead of the call to $view->get_title().
Comment #20
monish_deb commentedYa that could be also possible, but every time when you change your attachment Title you also have to change the text so I thought the $view->get_title() function will automatically fetch the title. I think with the help of any of the"Header" fields it will atleast show the title but that's not the appropriate way to achieve it.
Considering it as a feature request I am trying hard to provide a setting option to admin (check the snapshot) to show Title or not, on the basis of which Title header will append on the top of attachment content. Soon I will submit the patch with necessary changes in Core file.
Comment #21
rooby commentedSince this is not an issue restricted to the attachment display (it is common functionality for the title not to print in the view itself, as per #1) maybe it should be an option for all display types?
For example I might have a reason to display the title of a block view in the view, instead of as the block subject, or a page view display its title in the view, instead of as the page title.
If it is an option that is off by default it shouldn't hurt anyone to have it for all displays.
Maybe as per in this screen?

Comment #22
monish_deb commentedI second that :)
Comment #23
monish_deb commentedAfter doing lot of research I got the reason why the title is not rendered in attachment view. #1 is somehow correct in his statement "For most views, the title is rendered completely separately" that's why it show title in all other views (page, block, feed etc) except attachment which is just a attached section of other views. The reason why attachment Title shows in view "preview" and return '' in view display relies on (/views/theme/theme.inc at Line 86)
Here's the views_ui_context is only set TRUE by the function views_ui_preview() which returns the output of the preview for which attachment title is shown in view preview only.
Now I have provided a additional feature on the basis of which admin can show the attachment title only for attachment(check snapshot) because in some cases in doesn't make sense to show attachment title. I have submitted the patch and also tested in my local
Comment #24
rooby commentedThanks, I will test the patch when I get a chance.
Not sure what others think but I still feel it should not be only for attachment displays.
I think it should be an option for all display types.
Then it is more consistent for the user and it also covers more use cases, as there are use cases for this with other display types.
Note that that patch applies with patch -p2
Comment #26
rooby commentedThe patch fails to apply because it has been made from outside the views directory instead of inside.
It needs to apply fom inside the views directory with patch -p1
Comment #27
monish_deb commentedResubmitted the improvised patch.
Comment #28
rooby commentedComment #29
rdrh555 commentedUsing Drupal 7.23 & Views 7.x-3.7 tested this patch and works as advertised alleviating the need for adding the attachment title in a template file. One observation: this works fine if your title will use an h2, but if you attempt to override this by wrapping your title in an h3 in the UI, for example, this will result in a validation error. Otherwise, this is a fine solution.
@rooby I tested on a page view with 2 attachments. I'm for expanding this as I still had to hard code my first h2 in the global text area/template since the title of the page view was the actual page title.
Comment #30
monish_deb commentedIn fact I was thinking of having a 'style setting' option in Title change form like we have in case of Views field and in this case you can override with whichever tag you want, otherwise default will be h2. End output will be to have additional style setting for title of page, attachment etc.. which provides more flexibility.
What you think?
Comment #31
rdrh555 commentedI think that is a great plan and I really like the flexibility. I am happy to test whenever.
Comment #32
rooby commentedOne problem I have with this patch is that if my attachment view is empty the title still shows.
I would expect that if there were no results or empty text or anything like that then the title should disappear.
Comment #33
rooby commentedIs there a way to determine if there are any results or if any area handlers have been set to display for empty views etc. and not show the attachment?
Determining results is easy but I'm not sure about checking for handlers that are set to still show when there are no results.
Comment #34
rooby commentedInstead of trying to detect whether everything is empty I think it would be better to let the user decide based on results, like they do in other places.
This patch adds an additional yes/no selection to choose whether or not to show the title if there are no results.
Comment #35
rooby commentedHere is a new patch.
The difference is that when we check the settings for show title, title, etc. to apply to the attachment the old patch was using the parent view display handler to get the options.
This meant that if you had something like a hook_views_pre_view() that altered the view attachment and modified those settings your modifications wouldn't be used.
I change it to get the display options from the attachment view, not the patent view.
eg. instead of using $this->get_option it uses $view->display_handler->get_option.
Comment #36
rooby commentedThere is also a potential issue with us adding non-themeable markup.
We're adding the title with a H2 and themers can't really override that.
Comment #37
Anonymous (not verified) commentedThanks it works well on my website
Comment #38
darvanenLooks good and is working fine for me.
The title of a normal view (block for instance) is also an h2 that themers can't over-ride very easily - I think that's a problem that can be handled in another thread if it really becomes an issue.
Comment #39
transformative commentedThe patch in #35 worked for me when I tried it out. The title appeared in my attachment, as expected. (Oh, sorry, I didn't notice that this was already set to RBTC).
Comment #40
rooby commented@Darvanen:
I agree, it can be a follow up.
I think it needs to be done though as it could potentially cause people accessibility issues relating to heading hierarchy.
Comment #41
joelpittetThis looks great thanks. RTBC++
Comment #42
aporieBug seems to be back again : views 7.x-3.16
Comment #43
dioni commentedI can confirm that it continues in 7.x-3.18
Comment #44
dioni commentedComment #46
joelpittetLooks like this just fuzzed, but may need a re-roll.
Comment #47
damienmckennaReroll, and wrapped the theme() line.
Comment #48
damienmckennaCommitted. Thanks everyone.
Comment #51
andrew answer commentedWhat with D8?
Comment #52
sagesolutions commentedIs there a D8 patch for this? The title doesn't show on Drupal 8.8.1 for attachments
Comment #53
damienmckennaI couldn't find the exact same issue on D8, but I did find this: #2598502: Double escaping in views attachment titles