Hello,
I'd like to suggest a new feature for a future version of Views: the ability for multiple views to have the same path for their page displays, with the capability for Views to determine which view the path is referring to based on arguments (the determination part would, presumably, be PHP code entered by the administrator, ala argument validation in Views 2).
For example, two views that both have the page display path "cars/%". If the URL "root/cars/1968" is accessed, Views runs some (admin-specified) code, determines that the argument is numeric, and displays the view "cars_from_a_certain_year". On the other hand, if the URL "root/cars/Lotus" is accessed, Views runs some code, determines that the argument is non-numeric, and displays the view "cars_made_by_a_specific_company". Both of these views, "cars_from_a_certain_year" and "cars_made_by_a_specific_company", would have the same page display path ("cars/%").
I think this could be beneficial, since it more closely mimics how pages might be laid out in an actual directory structure and shortens paths for page displays.
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedCurrently multiple displays with the same view can have the same path (and FYI it will never be multiple views, it will only ever be multiple displays within the same view; this is due to complexity in the menu system) though right now only access is checked, not argument validation. I agree that argument validation should also be checked, but it's not an easy task unfortunately.
Comment #2
william_frane CreditAttribution: william_frane commentedMultiple displays of the same view with the same path would be just as useful. I've done some tests and currently it seems that if there are multiple displays (of the same view) with the same path the first display in the view to use the path is the only one that's ever shown when the path is accessed (so it's the same sort of limitation). If I'm missing something regarding the current functionality in this area (e.g. multiple displays with the same path can act in a manner similar to the hypothetical "cars/%" case I outlined above) I'd really appreciate any enlightenment.
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedAs I mentioned, it checks access. So if the current user doesn't have access to the view, (i.e, doesn't have the required role/permission) then it will check the next one.
Arguments are another story. Still need to work on that.
Comment #4
KarenS CreditAttribution: KarenS commented@william_frane - depending on what you're trying to accomplish, you may want to use attachments for this. You can create a view page at your given url and a series of attachments to that view for the various ways you want to display things. Then you'd need some custom code somewhere to hide/show the attachments based on your criteria. I'm not sure exactly how you'd do that - just giving you an idea to play with.
Comment #5
william_frane CreditAttribution: william_frane commentedKarenS, what do you mean by "attachments" in this context? (I assume you're not referring to file attachments.)
Comment #6
Jeffdo CreditAttribution: Jeffdo commented"Attachments"
The first quote's from the advanced help (/drupal/help/views/display-attachment), the second's from the announcement (http://drupal.org/node/277856) for the D6 Views 2, CCK 2, and Organic Groups release candidates.
The View Reference module came out July 1, the day before the release candidates, with similar functionality.
Comment #7
Dave.Ingram CreditAttribution: Dave.Ingram commentedI also find myself with a need for this functionality. A site I'm currently working on has different displays based on the depth of taxonomy terms. The problem is that the path is always taxonomy/term/tid, no matter how deep it goes, so I would need another way to choose the display besides path. In this case it would be by checking the term_parent and/or children in an argument.
Thanks!
Comment #8
abu3abdalla CreditAttribution: abu3abdalla commentedi think its not so hard , i am not developer but i think if we add visibility function for the page .
Comment #9
merlinofchaos CreditAttribution: merlinofchaos commentedNot helpful.
Comment #10
abu3abdalla CreditAttribution: abu3abdalla commentedi have made that but not as i said :)
my problem is : i have multi vocab and i need certain view page for every vocab. i mean taxonomy.
lets say for the first vocab taxonomies i need it node type and for the second vocab taxonomies i need it fields with certain fields.
i have solve it by my idea and i will write a tutorial for that but after i test my approce.
thanks
Comment #11
federico CreditAttribution: federico commentedabu3abdalla could you share your solution?
I have also two vocabs,
- for vocab1 I want to use view1 (page display - path: "taxonomy/term/%" - filter: vocab1)
- for vocab2 I want to use view2 (page display - path: "taxonomy/term/%" - filter: vocab2)
When I visit a vocab2 taxonomy page: http://example.com/vocab2/taxonomy/term/% , view1 comes to action first and filters the nodes, so (in my case) i get an empty view.
If I visit http://example.com/vocab1/taxonomy/term/% , view1 works fine
If I delete view1 and visit http://example.com/vocab2/taxonomy/term/% , view2 works fine.
I'll appreciate your help.
Federico
Comment #12
federico CreditAttribution: federico commentedduplicated comment, sorry
Comment #13
pjsz CreditAttribution: pjsz commentedlike federico, #11, i need the same thing -- many different taxonomy views filtered by node type, vocabulary and what ever else but still use the path /taxonomy/term/%. I'm using Views 2 in D6. I used the "taxonomy/term/%" path so that I could make URL Aliases for them and my term links rendered under all my nodes by the taxonomy module automatically are aliased like "products/learner_assessment" rather than "taxonomy/term/%". That is handy. But not having any of your new taxonomy links work is not good.
This hit me like a bombshell. So as it stands, the first view you make with a path "taxonomy/term/%" ( or any path ) is what will be called if the user has permission. Otherwise it will look for another view the user has permissions to use and the first one hit, is what is rendered. Is that correct for Views 2? I can see this is a tricky problem. What should views do? I don't know. Maybe the Views2 could check the filters and see if there a a vocab filter on the view then if the term is not in the vocab it tries the next view.
Did anyone figure out a good work around? I think i need to find a better way to alias my taxonomy links. But the problem is , i need my taxonomy views filtered differently for different vocabs so they have to go to different views. Maybe a taxonomy redirect -- /taxonomy/term/% would check which vocab and then change path to get to the proper view page. I guess i just need to override the code that is generating the term links and check the vocab type and rewrite them to the path to the correct view. That could work . Anyone else have any better ideas? It sure would be nice if views checked taxonomy vocab filter first. That would go a long way and sounds easy enough. I may try a patch for that first.
Thanks
Comment #14
merlinofchaos CreditAttribution: merlinofchaos commentedWhat people want isn't really something Views is meant to do, and is actually really an effect of taxonomy trying to do a little too much with not enough. Views itself is never going to give you multiple views for different taxonomies.
That said, you can accomplish that task using taxonomy redirect or Panels 3 which is currently in an early (somewhat buggy) beta.
Comment #15
ulo CreditAttribution: ulo commentedI also need to have different Pages for different Vocabularies.
The path for all of them is "taxonomy/term/%".
As argument i use the Taxonomy-TermID with a Taxonomy-Term-Validator where I am able to select the desired vocabulary. But that does not work as expected...
It would be nice if Views would allow for an "Action if argument is not valid" like "try next page" or so (instead of show all or nothing).
Comment #16
alienzed CreditAttribution: alienzed commentedchoosing the display based on arguments would be great! that way we could allow users to choose how many items per page they want to see without having to embed the view! if there's another way to do that, I'd love to know :)
Comment #17
calbasiTaxonomy redirect rules !! to bypass this issue :-)
Thanks a lot
Comment #18
JGO CreditAttribution: JGO commentedAny solution for this yet? I'm having the same problem with content taxonomy terms view :s
EDIT:
Found out that it can be done when using the attachments display.
Create an attachments display with these settings:
Attachment settings
Inherit arguments: Yes
Inherit exposed filters: No
Inherit pager: --> not important
Render pager: --> not important
Position: After
Attach to: Page
Than overide the arguments (and also filters if required) for this attachments display.
Also make sure that when arguments do not validate you chose: "display empty text"
Hopefully this is useful for someone!
----------------------------
JGO | http://www.e2s.be
----------------------------
Comment #19
gg4 CreditAttribution: gg4 commentedArguments are another story. Still need to work on that.
Would be useful. Subscribing.
Comment #20
caschbre CreditAttribution: caschbre commentedI tried JGO's solution in post #18 but I couldn't get it working for my scenario. Maybe that's because I'm not basing my views off of taxonomy. Here's my use-case that hopefully shows how two displays with the same path but different arguments would come in handy.
Use Case
Content Types
- Game (plain old content type)
- Team (group type)
- News (node reference for news about a Game; also may be posted to a Team group)
Views
- News about a game
--- path: node/%/discuss (argument = node reference field)
- News posted to a team group
--- path: node/%/discuss (argument = group nid)
My initial thoughts to choose which display to present would be...
pseudo logic
I know that's very basic, but it basically finds all available displays based on the path and then checks those displays for the type of arguments it accepts. If those arguments are available then use that display.
Comment #21
kla2t CreditAttribution: kla2t commentedsubscribe
Comment #22
tobykilroy CreditAttribution: tobykilroy commentedThanks JGO that worked perfectly for me!
Comment #23
candelas CreditAttribution: candelas commented@JGO you are a crack!
i was making things very complicated and your solution worked perfect and it is simple!!! :)
i think it is so good, that i put it in the documentation
http://drupal.org/node/1241852
Comment #24
HansKuiters CreditAttribution: HansKuiters commentedJGO: thanks for the solution, but I can't get it to work.
I have a view with a page display and an attachment display, set up like you described.
In the page display I have one argument Taxonomy: term ID (with depth) with Basic Validation, a couple of fields , no filters.
In the attachment display I have one argument Taxonomy: term ID (with depth) and one argument Taxonomie: Term ID depth modifier, Validator Taxonomy term with the wanted Vocab checked, Action to take if argument does not validate set to Display empty text, Filter set to one Node type.
When viewing terms from vocab A and vocab B, they both show nodes from all node types. Can you help me out here?
Comment #25
JGO CreditAttribution: JGO commentedHi,
I would assume that you don't hide it in one of the 2 cases ?
In both cases it should hide nodes when it's a view where they are not wanted.
Comment #26
pupp CreditAttribution: pupp commentedThe solution has worked for me, initially. I'll need to continue to play around with this a bit more as my requirements may get more complex. just as an fyi, my setup consists of both a store front and a blog. uc_catalog was simply not cutting it so i had to go on my own and build my displays with views 2. thanks for the help @JGO
Comment #27
GiorgosKif anybody is still struggling on this problem try any of the following projects
http://drupal.org/project/tvi
http://drupal.org/project/eva
http://drupal.org/project/taxonomy_display