How to pass taxonomy term from node context and to embedded view?

laken's picture

First, thanks to Earl and Sam for Panels 2 - an amazing contribution to Drupal! I'm having a ball with it, but have hit a roadblock that has me stymied for the moment:

I want to make a panel page that takes a node id (or a path alias) as argument, and displays the content of that node in one pane, while extracting the top taxonomy term from the node, and passing the taxonomy term as an argument to some views panes in the same panel page.

Here's a diagram of what I mean:

Path: article/nid or article/path-alias

+----------------------------------------------+----------------------------+
|                                              |                            |
|Article headline                              | more in International      |
|                                              | (view filters on Business  |
| (term: Business) ------------------------------>  term)                   |
|                                              |  - link to article 1       |
| article body....                             |  - link to article 2       |
|                                              |  - link to article 3       |
|                                              |                            |
+----------------------------------------------+----------------------------+

Here's the steps I've tried:

- create a view that filters by a taxonomy argument
- make a panel pane from that view
- make a panel page (2-column)
- under Context/Arguments, add "Node ID"
- under Context/Relationships, add "Term from Node" and select the vocabulary I want
- under Content, in the left panel, add "Node Content" from "Node Context"
- under Content, in the right panel, add the view pane I want

What I can't figure out is how to pass the Term context into the embedded view so it filters properly. Can Panels 2 do this?

If anyone could help, it would break a major logjam I'm having on my site. Thanks in advance!

Groups:
Login to post comments

Your view should filter by

merlinofchaos's picture
merlinofchaos - Tue, 2008-06-17 23:56

Your view should filter by taxonomy tid.

Your panel pane for that view should be set to require a taxonomy term context for your view.

Otherwise, what you suggest should work.


Wow, that is just the piece

laken's picture
laken - Wed, 2008-06-18 02:27

Wow, that is just the piece I needed - terrific! Amazing fast answer that has made my week.

Here's a small follow-up: Before you gave me the key to this, I was trying by putting the term id as a path argument to the panel, not using any contexts, and just passing that argument to the embedded views.

The views were set to Default: "display all values", and the views pane argument source was set to: "from panel argument."

While this didn't let me override display of specific nodes (which you've solved for me,) it did one great thing: if the category argument was absent, the views panes would still display, unfiltered (which is what I want).

With this new context approach, if the context is not present (e.g. the displayed node has no terms,) those embedded views don't display at all (because I imagine the "required context" is, well, required :-) )

So the question: Is there any way to mimic the other behavior, i.e. if there's no term context, the embedded views can still display, just unfiltered?


I'm trying to do the exact

imrook - Sun, 2008-09-14 14:57

I'm trying to do the exact same thing and having problems. I believe I have everything set up like alaken. Could someone review my configuration and see if I'm missing something obvious? Versions I'm using:

Drupal: 5.10
Views: 5.x-1.6
Panels: 5.x-2.0-rc1a and 5.x-2.x-dev

http://groups.drupal.org/files/view_pane_config.jpg
http://groups.drupal.org/files/panel_content_config.jpg
http://groups.drupal.org/files/panel_context_config.jpg

AttachmentSize
panel_context_config.jpg 51.42 KB
view_pane_config.jpg 27.95 KB
panel_content_config.jpg 53.98 KB

Follow up...

imrook - Sun, 2008-09-14 18:31

I just want to follow up on this in case someone else comes here on a search. I found I had to change the view type on the Views pane configuration to "Embedded" instead of "Page." As I didn't include that as part of my screenshots, it seems they weren't very helpful after all :) Hopefully this post saves someone else some time.


still struggling

thomasmuirhead - Wed, 2008-11-26 18:29

Hi there,

what I'm having difficulty with is I just don't get the options I see above. Where do I find these?
http://groups.drupal.org/files/view_pane_config.jpg

In the view pane, I just get the choice to Taxonomy Term ID: drop down from which I choose Term from nod (and then the normal pane options such as style)

I don't get: Argument Source, Required Context, Panel argument, Fixed Argument or Label

I'm using the same versions of things as you are? Any ideas?


ok understand this bit now

thomasmuirhead - Wed, 2008-11-26 19:05

One step at a time I suppose. I now realise you have to add the view as a panel pane.

Done that...configured it just as you guys have but get nothing coming through. Even though it's set to display all values I still get nothing through.


I think I'm trying to do something similar ...

ulfk - Thu, 2008-08-14 08:57

I have a view that returns all nodes of type X, created by user Y (uid from argument).

I created a Views Pane for this view.

And then embedded that Views Pane in a Panels Page which has a url of events/%. This works great for users who have created nodes of type X. However I get a "Page not found" for users who have not created any nodes of type X.

I have tried:
- setting my argument default to all values (Display all values etc)
- adding additional custom content to the Panel Page so that some text is always shown/can be defaulted to
- giving the Panel Page a static title
- giving the Panel Page a title that uses the %user context

None of the above prevent the "Page not found" from displaying when the uid doesn't have any nodes of type X associated with it. Any one else encountered this? Is this intentional? Is there a workaround?


Views Argument Display Empty Text

west_d_r - Sun, 2008-09-14 19:43

Have you tried setting your views argument to display Empty text if the argument is not present? Then fill in the empty text field with whatever you'd like to display to users who haven't provided content for that view. Not sure if that's what your trying to do.


Similar problem but some elaboration would be helpful

slake - Fri, 2008-10-31 21:25

I have a similar situation to the OP, except I'm attempting to display current room openings (view of open room nodes) for a collection of houses (individual pages for each house).

Path: house/nid

+----------------------------------------------+----------------------------+
|                                              |                            |
| House Title                                  | Rooms Availible to Rent    |
|                                              | (filters on vocab: House   |
| (term: HouseName1) ---------------------------------->  term)             |
|                                              |  - Room Opening 1          |
| House information....                        |  - Room Opening 2          |
|                                              |  - Room Opening 3          |
|                                              |                            |
+----------------------------------------------+----------------------------+

Like the OP, I've also tried similar steps:

  • create a View
    • filter by node -> type: House
    • filter by node -> Published: Published
    • filter by taxonomy -> term
  • make a panel pane from that view
  • make a panel page (2-column)
  • under Context/Arguments, add "Node ID"
  • under Context/Relationships, add "Term from Node" and select the vocabulary I want
  • under Context/Context, add "Taxonomy vocabulary" and select the vocabulary I want
  • under Content, in the left panel, add "Node Content" from "Node Context"
  • under Content, in the right panel, add the view pane I want

However, I have not been able to reap the same success from merlinofchaos's helpful advice.

In the Panel Pane display for the view, I also have added Taxonomy: Term ID to the Arguments section to display all values if the term isn't present. Additionally, I've configured the Argument Input in Pane Settings to have "Taxonomy: Term ID source:" be "From context" and the "Required context" to be "Taxonomy term".

But it doesn't seem to work, and I'm not sure why. Perhaps the most confusing aspect is how I'm supposed to configure the filter - Taxonomy: Term so that it filters based on the term that's passed to it. When I add the filter it asks me which vocabulary I want to use, I choose "House" and the "dropdown" method of selection. Then when I'm allowed to select the terms, I've so far left it blank, believing it would then select all the nodes no matter which house node ID was in the main panel.

What am I doing wrong? Would screen shots help? Any advice would be wonderful. Thanks


Similar scenario with advertising

trevorkjorlien's picture
trevorkjorlien - Wed, 2009-07-15 00:56

I'm building a restaurant directory, and I've created a restaurant content type with taxonomies attached to it (price, geographic zone, cuisine type). I've also made a View with exposed filters so people can choose by drop-downs what sort of restaurant they're looking for. So if somebody chooses "Cajun", it will only show restaurants that have been tagged under "Cajun". Pretty simple.

However, we need to sell advertising in our directory, and what we want to happen is that when somebody selects "Cajun" an ad for a Cajun restaurant will appear above the search results. Or if somebody selects the geographic zone "North", an ad for the north side of the city will appear. Hope that's clear to understand.

I've installed the Ad Module, and I've tweaked the default content type that it creates with the very same taxonomies I used for the restaurant content type (price, geographic zone, cuisine type). So for example, I have some restaurants created that are tagged under "Cajun" and I've made an ad also tagged under "Cajun". As I said before, we would want somebody to select Cajun from the drop-down, and that Cajun ad would show above.

I'm new to Context in Panels, but from what I've been reading, this thread is close to what I'm trying to achieve. I've made a panel page, and have two panes; one on the bottom for the View that shows the drop-downs and the search results, and the top is where I would like the relevant ad to appear once a selection is made. Here's some mockups of what I would like to happen (with minimal styling... hope you can decipher what I'm getting at):

http://trevorkjorlien.com/storage/views_and_ads/dish_home.jpg
http://trevorkjorlien.com/storage/views_and_ads/dish_africa.jpg
http://trevorkjorlien.com/storage/views_and_ads/dish_downtown.jpg

Any help appreciated.