So eaton and I just stumbled across an interesting issue that we're not quite sure how to solve.

Right now when attaching a view to a node (and a user profile), the display is generated via $view->execute_display() and the raw results are then stuck into the $node->content array as an item type, because that gives us a #title property. However, item assumes that it's part of a form and therefore we get form HTML, such as "label". That is ungood.

We also realized that when we ask Views for the display template in the Theme:information window, we get a PHP error because views_attach does not in fact provide a template file at all, and views tries to look for views_view.tpl.php in the views_attach directory. That is ungood.

So... what is actually happening? Is the template file simply bypassed because we're calling execute_display()? Is it falling back to the views-default template? It would seem to, since attached displays work. But then why are we getting an error? On top of that, there's still the issue with the title being poorly placed.

So the working theory is to add a template file that is a clone of views-view.tpl.php but also has place to put the $title in there if set, which is only set if the user checks the appropriate checkbox. And then... do we switch to views_embed_view(), or is execute_display() correct? We're not actually sure.

Help us, merlin, help us!

CommentFileSizeAuthor
#3 views_attach-theme.patch5.45 KBAnonymous (not verified)
#2 views_attach-theme.patch8.7 KBAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

You'd stick with execute_display(). As a display, you have the right and privilege of registering a theme function. You'd probably register views_attach_view or something along those lines.

Anonymous’s picture

FileSize
8.7 KB
Anonymous’s picture

FileSize
5.45 KB

The last patch had mistakes. Check this one out instead.

gleroux02’s picture

I applied the patch, and the tpl is working. The only problem that I am having is that when I try to copy the tpl out into a theme directory to make changes to it, views picks up the new tpl file but the view does not print. When I took a look at $variables the view object was still there, but rows and everything else that gets printed in the tpl were not.

Pasqualle’s picture

Anonymous’s picture

Pasqualle, are you saying that this is an issue for this patch or is this a larger Views issue?

Pasqualle’s picture

I am saying that views module should be able to suggest the template names for new display types. I think it has all the info for the correct template names. So, I would try to fix the issue in views..

Crell’s picture

Status: Active » Needs review

There's other issues that this patch addresses such as the title handling, so I'm inclined to go ahead with it anyway even if Views gets updated later.

eabrand’s picture

Assigned: Unassigned » eabrand
Status: Needs review » Reviewed & tested by the community

When in doubt, flush the whole cache, not just the theme registry.

Crell’s picture

Status: Reviewed & tested by the community » Fixed

Sage advise. :-) Committed. Thanks all!

The next step is probably to do the same for the user profile display, since it's also missing a template.

merlinofchaos’s picture

Status: Fixed » Active

Um. You cloned views-view.tpl.php? That's probably not good.

'theme path' might have been a better choice.

merlinofchaos’s picture

Status: Active » Fixed

Oh well you have a $title in your display so of course you have a clone. Sorry, people in another queue are doing the wrong thing due to this example. =)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.