Ok, so you've used Panels for a while and gotten used to managing contexts. Here's a new challenge for you: Views as context.
What's the point?
Point number one is that Panels can output individual elements from a view loaded as a context. This is most interesting when outputting stuff like row 1, 3 and 5 in one pane and row 2, 4 and 6 in another. And – yes – you can choose which fields from the view to output.
Point number two is just so much cooler. You can add an object from the view as a new context. This means that you can pick out the topmost node and display some extra information about that, without having to resort to strange hacks and view calls inside custom-written mini-modules.
What really sends my brain spinning is what you can do if you don't restrict point number two to nodes. Get a list of taxonomy terms as a View context, and send back hit 1 and 2 to fetch articles in the two most popular tags for the current post. Or make a list of newest articles, and call different variants of the panel depending on settings in the first hit. And so on. The View context isn't about embedding views into panels, but to provide Panels with a query tool.
DISCLAIMER: Every Wednesday (or so) someone at NodeOne makes an unprestigious presentation about something related to Drupal. The presentation is mainly for internal use, but we have decided to share recordings of the presentations to anyone interested. They are shared as-is – there screencast is uncut, sometimes interrupted, can contain noises and bad sound capture. They can also contain useful information about Drupal.
Comments
Gäst
August 31, 2010This is a really nice feature and thank you for creating a video tutorial!
I have created a context display for my frontpage and one for my taxonomy terms. When enabling the term view panel and adding a context I now get two context_views in the drop down list (since I have created two). I want to choose the the taxonomy view but it won't let me. I'm selecting it, save the panel and visit one of my taxonomy pages, somehow it has not stored/or choosed the context view I selected, it chooses the first context_view. The views works fine, I have tested both of them without using panels. Is this a bug or just me? (probably the last).
Scott
October 8, 2010Excellent.
Now try try THIS with View context:
Pull the node.title from that context, and set it as Panel Page title.
It seems to work as long as the view does not need arguments. Panels doesn't seem send arguments to view context.
So if you had term as your panels context... panels has a term and term-id context. Good. Now use a view that takes TID as a argument, field returns node title. It won't work. (You'll get fields back into the Panel View Context... but only if the view returns rows without requiring arguments... so you just get the default view result).
Johan Falk
October 9, 2010Ah, yes. Very true indeed.
There is (currently) no way to give arguments to the view you call as a context in Panels.
It would be useful to be able to send arguments, but my guess is that it will be <em>difficult</em> to do this in a generalised way, since contexts are a possible arguments – and you can't load contexts before you load contexts. :-/
Gäst
October 22, 2010>It would be useful to be able to send arguments, but my guess is that it will be difficult to do this in a generalised way, since contexts are a possible arguments – and you can’t load contexts before you load contexts. :-/
Yes, it does seem like two passes are needed. One to set the page contexts, and another to fire off the Views Context. I do not know the internals that much, and had no idea the problem would be of this nature. Re-working contexts would probably be something not to be done lightly, and therefore this will likely get kicked down the schedule for other priorities. :-/
One *awesome* hack would be to allow selecting a Panel to set Page Title based on the Node.Title. I now expect this would suffer from the same problem you describe, but perhaps with a limited form like I suggest then it might be possible to "hack in" something that's hardcoded to look for node title. This might be easier to roll out anyways.
My solution will ultimately be to export the views and panels, and hack them to essentially replicate the same general queries "outside" Panels and Views, and set Page Title that way. It feels unclean, but at least the solution is sustainable.
Panels can get the Page Title from the View Title. This would solve the problem nicely. Unfortunately, Views Title can not obtain values of View fields (not until you export the View anyways).
merlinofchaos
October 30, 2010This is on my TODO list -- the second pass is called 'relationships' and there needs to be a view context relationship where you can take contexts as input and attach them to arguments. I know about how to do it, I just haven't had a chance to write it.
mansspams
July 13, 2011I am looking for a way to add relationship to node with a field referencing to node being viewed. Second pass would make it possible. Maybe there are other clean solutions like ctools plugin that does that?
Avi Alkalay
December 8, 2010Thanks for this video. I'm having a bad time to understand Panels Contexts.
In the end, Context seems to be a region in memory where you put variables and Panes can access them later. But I'm not sure yet. Well, this video has helped me to make a better idea anyway.
Thanks !
интернет казино
January 15, 2011Статья отличная, но советую дополнить материалом, будет больше полезна!
Johan Falk
January 15, 2011(From Google Translate: "The article was excellent, but I advise you to supplement the material would be more helpful!")
Thanks for the kind words and the advice!
Lukas von Blarer
December 19, 2011@merlinofchaos: Is there a issue for the "send arguments" feature?
Johan Falk
December 19, 2011 I actually think this is already implemented, at least in the D7 version. :-)Lukas von Blarer
December 20, 2011I don't think so. Or did this happen in the past two weeks?