I have attachment displays which I've added to a page display and I want the attachment to show its title. I have set the attachment display titles as overridden properties in Views. However, the $title variable in the related template file is empty ("" string) and I can't figure out why it's not showing. Can I get direction, please?


merlinofchaos’s picture

Status: Active » Fixed

Attachments 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.

BordenR’s picture

Category: support » feature
Status: Fixed » Active

Sweet. 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.

BordenR’s picture

And, 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 >.

dawehner’s picture

Did you tryed to use the title token in the header of the attachment display?

BordenR’s picture

These are my available replacement patterns when I select Header -> Global: Text Area:

%1 == Content: Has taxonomy term ID (with depth) title
!1 == Content: Has taxonomy term ID (with depth) input
%2 == Content: Has taxonomy term ID depth modifier title
!2 == Content: Has taxonomy term ID depth modifier input
%3 == Content: Date - start date (field_date) title
!3 == Content: Date - start date (field_date) input

Am I supposed to have the token module installed or something?

merlinofchaos’s picture

Ah. Yes. There's no token for the title. So not much of a workaround. :/

BordenR’s picture

What'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.

merlinofchaos’s picture

From the template, $view->get_title() should be all you need.

BordenR’s picture

Unfortunately, no. $view->get_title() gives me the taxonomy term, not the attachment display's title which I set.

merlinofchaos’s picture

Does your argument have a title that overrides the regular title?

BordenR’s picture

Yes, 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).

fietserwin’s picture

#304969: Show title for attachment displays is a duplicate but for 6.x-3.x

moonray’s picture

Running into the same problem. Will the patch for D6 (modified to work with D7 version) work? Is it a good solution?

duckx’s picture

same issue too. have a page display and made an attachment and the total view doesnt show any title

sorensong’s picture

i love drupal support.

rooby’s picture

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?

rooby’s picture

The 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.

monish_deb’s picture

I have been able to show the Attachment title by using $view as available variable for "Header -> Global: PHP". This is the Output code:

echo "



I am not sure whether it is a correct approach but for now it served my purpose.

rooby’s picture


You can also use filtered HTML and just enter the title text instead of the call to $view->get_title().

monish_deb’s picture

7.85 KB
7.26 KB

Ya 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.

rooby’s picture

Since 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?

monish_deb’s picture

I second that :)

monish_deb’s picture

2.72 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1269592.patch. Unable to apply patch. See the log in the details link for more information. View
34.18 KB

After 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)

  // @todo: Figure out whether this belongs into views_ui_preprocess_views_view.
  // Render title for the admin preview.
  $vars['title'] = !empty($view->views_ui_context) ? filter_xss_admin($view->get_title()) : '';

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

rooby’s picture

Version: 7.x-3.0-rc1 » 7.x-3.x-dev
Status: Active » Needs review

Thanks, 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

Status: Needs review » Needs work

The last submitted patch, 1269592.patch, failed testing.

rooby’s picture

The 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

monish_deb’s picture

2.43 KB
PASSED: [[SimpleTest]]: [MySQL] 1,658 pass(es). View

Resubmitted the improvised patch.

rooby’s picture

Status: Needs work » Needs review
rdrh555’s picture

Status: Needs review » Reviewed & tested by the community

Using 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.

monish_deb’s picture

In 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?

rdrh555’s picture

I think that is a great plan and I really like the flexibility. I am happy to test whenever.

rooby’s picture

Issue summary: View changes

One 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.

rooby’s picture

Status: Reviewed & tested by the community » Needs work

Is 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.

rooby’s picture

Status: Needs work » Needs review
3.6 KB
None View

Instead 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.

rooby’s picture

3.67 KB
None View

Here 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.

rooby’s picture

There 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.

Tim Prys’s picture

Thanks it works well on my website

Darvanen’s picture

Status: Needs review » Reviewed & tested by the community

Looks 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.

transformative’s picture

The 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).

rooby’s picture


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.

joelpittet’s picture

This looks great thanks. RTBC++

Aporie’s picture

Bug seems to be back again : views 7.x-3.16