Calendar view with different filters

davidjmcq - October 10, 2009 - 01:53

I want to display a calendar view filtered by different taxonomy terms. Do I have to clone the view for each term or is there another way to do it?

For instance, the client clicks on a regional map and gets a differently filtered calendar depending on region.

You can create another page within the same view

Cayenne - October 10, 2009 - 13:02

And then override the taxonomy filter for the second page. Then link to the new page.

There is a fancier way to do it with arguments, but I have not got the hang of that yet, and my way works just fine.

---------------------

"He's said to be outspoken, but nobody's actually seen anyone do it"

extracting arguments from href for a View

davidjmcq - October 11, 2009 - 23:45

Answering my own question to a limited degree:

On the referring page use href="example.com/calendar_path/xxx" where xxx is not a real file, but an argument for the calendar.

Set the page "path" on the calendar view to calendar_path/%, where % will substitute xxx in the referring page.

xxx is now available as an argument to the view. In order to extract the argument I did the following steps:

  • Click + next to Arguments
  • Add "taxonomy: term", then "add"
  • In "title" you can put include "%1" which will insert the first argument captured from % in the path (see above)
  • click "provide default argument"
  • in "Provide default argument options" click "PHP code"
  • insert the code: "return arg(1);" (without the quotes)
  • under "Validator options" choose "taxonomy term"
  • choose the taxonomy you need
  • various options after that, none of which applied to my situation
  • click "update default display"
  • don't forget to save the view!

The argument extracted from the referring href is now effectively a filter for this view!

This all worked for me. Your situation will probably need different settings.

What was not CLEAR in other doco's that I read was that the path containing the argument is not a real file system path. That confused the hell out of me. That path does NOT EXIST on the file system.

Another thing to watch is that the number 1 referred to by arg(1) in the PHP code is actually the 2nd item in the path, because PHP starts counting from zero. Therefore"calendar_path" in my example would have been arg(0)". That's not obvious if you aren't a coder.

When I was trying to figure this out I was told that I don't need the PHP snippet (by someone on irc), but I can't see how to do it without the PHP. Maybe someone else can tell me.

 
 

Drupal is a registered trademark of Dries Buytaert.