I've been working with Views 2 "Attachment" displays to try to re-create this page from my current site in Drupal. The need for the Attachment displays is due to the groupings or "sub listings" you can see on the page (e.g. Interfaces & Layout, Special Effects, etc), which are taxonomy terms in a "Tutorial Type" vocabulary in my Drupal version of the page.

I've attached an annotated screenshot below of my Views page's output at this point (I have 2 taxonomy terms defined, and two Tutorial nodes, one assigned to each term... I currently have 1 Page display, and 2 Attachment displays which show listings of nodes that match each of the taxonomy terms).

I've run into a few questions I'm still stumped on after pouring over the Views UI:

  1. Is it possible to rearrange Attachment displays, or are they stuck in the order they were originally created?
  2. Is it possible to show an Attachment display's "Title"? I've configured Basic settings > Title to a custom Title for each Attachment display, but the names never show up on the Page display where the Attachments are connected. The Title is set to Override on the Attachment displays, so I'm not sure why it's not being used.

If I'm going about making this page all wrong I would be quite grateful for any advice to send me off in the right direction. Any advice would be greatly appreciated - thanks!

~ Tiny side node: I noticed there's no "attachment displays" component in the Views issue submission form (though there is for Page, Block, and Feed displays), so I have used Miscellaneous.

- David

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

1) right now rearranging displays is a minor missing feature. In a pinch, you can rearrange them by changing the 'position' field for the displays in the database. It's not exactly convenient to do so, I realize, but rearranging displays is not a common need. In fact, it's taken 3 months for someone to ask about it. =)

2) Hm. Attachment displays don't actually use their titles. This is because titles are usually handled externally when views are rendered, and I admit I didn't think to include title rendering with attachments. Most often, I've found titles are unwanted on attachments anyway. You can possibly mimic titles by putting a title in the header section, which does get used, or alternatively creating a views-view--viewname--displayid.tpl.php which displays the title you want.

domesticat’s picture

Status: Active » Closed (fixed)

Performing a mass closing of all issues over 180 days old. Please reopen if needed.

will_in_wi’s picture

Version: 6.x-2.0-rc1 » 6.x-2.x-dev
Category: support » feature
Status: Closed (fixed) » Active

This is still a problem. I need this, although the database workaround should work for me. Marking as a feature request.

ximo’s picture

Version: 6.x-2.x-dev » 6.x-3.x-dev

(I've heard that part #1 of this issue (rearranging displays) is planned for Views 3.x, and 2.x won't accept any new features AFAIK. I also haven't seen any issues for #2 (show attachment titles), so I'll bring this one back to life instead of creating a new.)

Having titles displayed on attachments would be a very useful feature. Like other display types, attachments have a Title setting, it just doesn't output it.

I've looked a bit into how attachments are rendered and I think I see why it hasn't been implemented in the first place.. as far as I can see, attachments are rendered without going through the preprocess/render function for views that exposes the title to the theme layer. I couldn't find a suitable hook to expose the title, so what I did was to simply add the following to a views-view-list--nameofmyview--attachment.tpl.php file:

$title = $view->display[$view->current_display]->display_options['title'];

This works, for anyone needing a fix for Views 2.x.

Would be great if this was a feature in Views 3.x though. Should be fairly easy..?

ximo’s picture

Title: Attachment displays: rearranging them and showing Titles » Show title for attachment displays

(I'm just changing title, don't mind me...)

marcvangend’s picture

Re #4: Thanks for the code. Views attachments do go through preprocess functions. This code works for me in template.php:

function YOURTHEME_preprocess_views_view_unformatted__attachment(&$vars) {
  $vars['title'] = $vars['view']->display[$vars['view']->current_display]->display_options['title'];
}

The rules for creating your preprocess function name:
1. start with YOURTHEME_preprocess_ where YOURTHEME is replaced with the name of your theme
2. take the template filename, cut of the '.tpl.php' part, replace all dashes with underscores and place that after the first part

[edit: typo]

SocialNicheGuru’s picture

subscribing- thanks

Edit:

I placed this in my template.php file but it didn't work.

function THEME_preprocess_views_view__attachment(&$vars)

joachim’s picture

+1 to titles showing on attachments.
Useful for doing things that grouping can't, such as in my case showing several nodequeues in an arbitrary order.

delmarr’s picture

I have just run into the same scenario as the originator of this thread.

I am stacking attachments on top of each other.

Issues

1. reordering attachments (thanks for the suggested solution merlinofchaos, wish it was abit more user-friendly)

2. need an option to display titles of attachments

thanks

ximo’s picture

Since people seem to come here looking for answers, I thought I'd answer some of the questions. This is not a support issue though, I recommend trying the forum or #drupal-support on IRC if you need more assistance.

#7:
For THEME_preprocess_views_view__attachment() to be picked up by Views, you must flush Drupal's theme registry. See button for this in your view's "Theme information" section. And you'll obviously need a views-view--attachment.tpl.php file to output the $title variable created by the preprocess function.

#9:
Here's another way to reorder displays, if for some reason you don't have direct access to the database:

  1. Export the view
  2. Change the order of your displays by hand (moving chunks of code up/down –– be careful not to mess up)
  3. Delete your original view
  4. Import the view again

Fairly tricky, so be careful to keep a backup of the original export when doing this.

benschaaf’s picture

I agree with merlin's (#1) second paragraph. The "Header" section works just fine for attachments.

Thanks merlinofchaos!

dawehner’s picture

Status: Active » Fixed

In views3 you can reorder displays via the ui. I don't see the need for the feature request see #1

marcvangend’s picture

Status: Fixed » Active

@dereine: I tend to disagree. You don't see the need for titles on attachments, but we have half a dozen people here who have indicated that they do need it.

Two observations:
1) An attachment has a 'title' value.
2) The template (ie. views-view-unformatted.tpl.php) already contains the code to show the title:

<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>

IMHO, it doesn't make sense that those two are not connected in any way.

I do understand that attachment titles are often not needed. Maybe a sensible way of implementing attachment titles would be to hide the (inherited) title by default, but show it once it has been overridden.

If I had a better understanding of the Views module, I would be submitting a patch now. If you point me in the right direction (which function or class to edit) I would be happy to give it a go. Right now, I'm only setting this back to active.

dawehner’s picture

One problem is that its not the case currently.
So we need a way to add this, but disable it by default. I don't get why a header is not enough.

marcvangend’s picture

I don't quite understand what you're saying - what is not the case currently? An attachment does have a title property. I exported a test view and it contains these lines:

/* Display: Attachment */
$handler = $view->new_display('attachment', 'Attachment', 'attachment_1');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['title'] = 'This is my attachment title';

I'd guess that it's pretty easy to check if display_options['title'] is set and pass it on to the template as $vars['title']. That would effectively mean that the title of an attachment is only shown when it's explicitly set.

Of course you can also use the header for this. Let me explain why I would prefer the title.
- IMHO, using the title property is easier and more intuitive.
- Because it uses existing template code (see #13), the user will get more consistent html output with less effort.
- It also prevents the "WTF?!" moment that I experienced when I added a title, inspected the tpl.php and had to figure out why it wasn't displayed.
- Last but not least: using the header for a title feels hackish, especially when the title property is already present.

dawehner’s picture


I don't quite understand what you're saying - what is not the case currently? An attachment does have a title property. I exported a test view and it contains these lines:

Sure but the title is not displayed yet. I bet when this will be just enabled, there will be 20 new issues complaining about it.

I understand your feature request...

marcvangend’s picture

Dereine, I am sure that you have better insight in what Views users will and will not understand. I respect that fact that in the end the maintainers will decide, not me. I just hope that you will base your decisions on what you think is the way forward with this module, not on the fear for a slightly longer issue queue.

Personally, I don't think that you will find 20 people complaining about a title that is disabled by default and can be easily disabled when it does show up. However, when they do show up, you can give them my email address. I'll be happy to help them.

OK, I made my point, that's all I can do. I'll shut up now :-)

merlinofchaos’s picture

Two observations:
1) An attachment has a 'title' value.
2) The template (ie. views-view-unformatted.tpl.php) already contains the code to show the title:

That $title is not the view title, that is the style title. This field is only used when the grouping field is set in the style options, which causes the style to be displayed multiple times. The fact that they are named the same is unfortunate, and a side effect of Views' organic growth.

Normally, the display title is never displayed by Views. Pages display their title completely separately from the view content, as do blocks, and these are the two main displays. For that reason, the actual view title does not appear anywhere in Views templates at all.

It might be plausible for the attach_to() method of views_plugin_display_attachment to render the title if there is one. If that is the case then it isn't something that will end up in the templates unless we have views-view-attachment.tpl.php which is more or less views-view.tpl.php but with the title field. I'm not really enthused with either solution.

merlinofchaos’s picture

As a pretty easy workaround, you could set up a views-view.tpl.php on your own sites that prints $view->get_title() for the title on the attachments.

Note that similar issues exist when using views_embed_view() which also does not print the title (because Views never actually prints the title of a view).

mstrelan’s picture

+1 for both parts of the original request

truyenle’s picture

#1 ->2) work for me to, use the header to mimic it.

But I do want subscribe to this also.

mastoll’s picture

How does one "use the header to mimic" the title? Especially in cases where you are stacking attachment displays on a page? Does each attachment have its own header?

geerlingguy’s picture

Subscribe - would like titles to display for attachments (if a title is given).

jstoller’s picture

@mastoll: Yes, you can give each view display its own header. This header can use any available input format (including php), so you can put something like...

<h2>Your title here</h2>

...in the header and it'll look like a title to your users. I had to do this recently myself, when using the Views Attach module. That being said, I also think this is a kludgey workaround. I would have much preferred a solution where I could just display the views title.

xjm’s picture

Tracking.

matt2000’s picture

Status: Active » Needs review
FileSize
1.35 KB

I also ran into a need for this on a project using the viewfield module. So it seems common enough that it's worth making it easier for themers. Here's a patch.

dawehner’s picture

Status: Needs review » Needs work

+  $vars['display_title'] = $view->get_title();

See other code, in template_preprocess_views_view_rss

   else {
    $title = $view->get_title();
  }
  $vars['title'] = check_plain($title);

So i suggest to use the name "title" for the variable and also apply check_plain

But the rest looks fine ;)

marcvangend’s picture

Status: Needs work » Needs review

I like the patch (not tested yet), because it adds the possibility of printing the title, without unexpectedly introducing a title when people upgrade.

dawehner’s picture

Status: Needs review » Needs work

Reset status. I hope this is okay

marcvangend’s picture

@#27: I'm surprised that you are suggesting to use $vars['title'] for this, because in #16 you said "I bet when this will be just enabled, there will be 20 new issues complaining about it." Putting the title in $vars['title'] would immediately cause existing templates to show attachment titles, which is exactly what you want to avoid, right?

Fr0s7’s picture

#19 accomplished what I was looking for:

<?php print $view->get_title(); ?>

Thanks merlin!

DaniG2k’s picture

+1 for both parts of the original request

fietserwin’s picture

#1269592: Attachment display title not showing is a duplicate but for 7.x-3.x.

dww’s picture

I also need this. Especially since if you have an attachment configured to render before another display, it actually gets inserted between the "parent" display's header and content. ;) So, instead of seeing this:

Attachment header
Attachment content
Page header
Page content

You end up seeing this:

Page header
Attachment header
Attachment content
Page content

So, you can't use headers to label or title your attachments unless you always use 'after'...

matt2000’s picture

Status: Needs work » Needs review
FileSize
1.36 KB

Rerolled to use filter_xss() on the display title. I did not change from 'title' to 'display_title' for the reason stated in #30, and also because 'title' may already be defined as something else, so I wanted to leave open the possibility of using both.

Status: Needs review » Needs work

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

couturier’s picture

Status: Needs work » Closed (won't fix)

Since most people are working in D7 or D8 and this is a very old issue, I am closing. When D8 is released in less than a year, support for D6 will be dropped.

ifernando’s picture

For #2 it is easy to create a header with a Global Text Area and the following content:

<h1 class="page-title">Title</h1>