By drupalzack on
I'm trying to do this with the story node type.
www.example.com/story should list stories submitted by all users
www.example.com/story/uid should list story by the uid
Can I achieve both using a single view rather than creating two separate views??
Thanks!
Comments
views create a web page (in
views create a web page (in your case) and each web page should have a unique url, which makes it impossible to create one page for displaying different information
hth
Yes, it can
...if you use the arguments feature. The uid would be the arg.
See here:
http://drupal.org/node/54455
And here if you wanna get tricky:
http://drupal.org/node/70145
-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com
-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com
Thanks 'As If'. I tried
Thanks 'As If'. I tried using argument handling, the problem is the argument handling code is executed only *if* an argument is provided.
So this will work:
example.com/story/all
example.com/story/5
But this will not work
example.com/story
If argument handling worked even if no args are supplied then I can do an if check for no args and assign args[0]='all' to get a list of all stories by all users
The other solution is to map story to /story/all ... I'll see how that goes! :) Meanwhile if others have any ideas, do share! :)
args[1]
In the edit view page, make the URL like this:
story/$argThen in the argument handling code, put this:
It's args[1] you want to set, not args[0]. args[0] is "story".
LVX
TF
-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com
-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com
That didn't work either.
That didn't work either. The arguments code only gets executed when the view detects an argument.
www.example.com/4 works
www.example.com/all works (of course I've setup all as wildcard)
www.example.com doesn't, since the arguments code is not even touched.
Is my views module broken, is this a bug or is this the default behaviour?
You can set the argument behavior
Look at the "default" drop down box in arguments. It allows you to set the behavior of the argument when no argument value is passed. It defaults to "Return Page Not Found," but you can easily change it to "Return All Values."
thanks for taking the time
thanks for taking the time to reply. I tried that too... here's my view
for this test I'm forcing args[1] to always return 'all'. that part of the arg. code never gets executed if the url doesn't have a parameter. But if I type in exampe.com/test/8 then the arg code gets executed. without the paramete I always get 'page not found' even after changing the type to return all rows.
hmm
Zack, I did some testing and this general approach works on my 5.1 installation. HOWEVER, assigning the $arg in the URL field (of the edit view page) was problematic, as you have discovered. I have found 2 ways to get around this:
Other stuff...
I also changed my argument handler so I could filter by multiple taxonomy terms (up to 4). In your case this might be something like "stories by userID" AND "murder mysteries" or whatever. Of course I also had to set up an argument (Taxonomy: Term ID) for each of those terms. It works even if some args are missing, it works with no args at all. Most interestingly, it doesn't even care what order the args are typed in. For instance, I didn't expect this URL to work, but it did... example.com/story/3///18
If you need this kind of capability, do something like this to your arg handler. (I used * instead of all but I really doubt that makes any difference)...
It works. Don't give up.
-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com
-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com
Thank you 'As if'! that was
Thank you 'As if'! that was a very detailed explanation and gives a very clear understanding of args with views. It is because of users like you, Drupal is such an exciting platform to work on.
Your experiment with $args is very interesting. Using aliases will be taking the easy way out! :) I'll use views without explicitly specifying $arg. That should solve my problem.