Search This Blog

Loading...

Sunday, April 19, 2009

Passing Arguments from Panel to Views in Drupal

As ridiculous as it sounds, passing arguments from panel to views in Drupal 6 is a very, very difficult job, judging from the responses collected from the official Drupal Forum. I myself spent quite a lot of times wrestling over it. So I think it's worthwhile for me to post the solution.

Here's how you can pass an argument from a panel to a view in Drupal.

  1. First of all, of course you need to have Views Module and Panels Module installed.
  2. Go to admin/build/views, choose the View you want to edit. Assuming that in this case, you want to define Taxonomy Term as the argument. So you will have to define the Arguments field as follows ( here's a tutorial on how to define a View)

  3. Now, go to your Panels page ( admin/panels/panel-page), Set the Path at the Settings tab as faculty/%. This means that the term after faculty/ will be the argument. For example, if your URL is faculty/abc, then abc will be the argument.
  4. Go to the Context tab, at the Arguments section, choose Taxonomy Term, and click Add argument. At the Edit argument form, set the Identifier as "my term", and the keyword as "term". Set the Argument type as "Term name", as shown below:



  5. Click OK.
  6. Go to Content tab, Select the View that you defined in step 1, make sure you choose the panel pane selection.
  7. At the Configure Panel pane form, make sure you choose "No context" as the Taxonomy Term, check the Send Arguments box. In the Arguments field there, type in %term

  8. Note that you must set the Taxonomy Term to No Context, or else the view won't work. I don't know why, most probably it's a bug.
  9. And that's it!
That's how I got my panel and views to work together in Drupal. Do let me know whether it works on your site!

14 comments:

macode said...

How can I pass the argument over the url?

Soon Hui said...

Hi macode,

You can just typed in http://yourdrupalsite.com/faculty/5 in the url, and 5 will be collected as the argument.

Adam Theo said...

Thanks very much for this tutorial. Because of it, I was finally able to use Panels with My Views inside my Organic Groups. This had proven to be impossible for days.

Anders said...

This was a great post, for the first time I managed to get Panels and views work together with arguments. Great work!

Anonymous said...

I found this site using [url=http://google.com]google.com[/url] And i want to thank you for your work. You have done really very good site. Great work, great site! Thank you!

Sorry for offtopic

射手 said...

hi,about the step 3(setting panels path),I did it as your instruction,
but I got below error message:
"You cannot have an unnamed placeholder (% or ! by itself). Please name your placeholder by adding a short piece of descriptive text to the % or !, such as %user or %node.“,
any suggestion?

my enviroment is panels-3.2. drupal6.

Khizer Jalal said...

same problem on my side? any solution?

Paddy said...

This seems to be the setup to use for drupal 6. Any idea of what changes are required to do the same thing in drupal 7?

Samuel Stidham said...
This comment has been removed by the author.
Samuel Stidham said...

There's an easier way to pass arguments from a Panel to a View in Drupal 6.

Follow all the steps to configure the View with an argument.

Panel:

Set the Path: Shop/%category

(category will be my taxonomy term)

Arguments:

%category context -> Taxonomy term: ID (select Term name as its operation).

Then, for the panel conent: PHP input type
views_embed_view('uc_products','default',arg(1));

using the arg() command, you pass the argument you want to pass to the view.

Configuring all those extra settings is not necessary.

As you can tell, I'm using Ubercart with this.

sathyasharepoint said...

Hi,
I like to know one thing in views and panels in drupal..For example I need to create some contents with in the panel like this url:http://drupalfun.com/. In this url they created some links within the panel. How can i create and call links within the panel..please reply me..thanks in advance..

Vizulefllry said...

THANK YOU SO MUCH! Hours of trying to figure this out and numerous tutorials to no avail.... and your simple tutorial FINALLY made it work.

Vizulefllry said...

THANK YOU SO MUCH! Hours of trying to figure this out and numerous tutorials to no avail.... and your simple tutorial FINALLY made it work.

Flex Sin said...

Thanks for this wonderful tutorial, my question is: Can we use Media Atom Reference field for image in Slideshow from Scald Media Management module instead of using field type Image? drupal