Arguments not reacting as expected

Events happening in the community are now at Drupal community events on www.drupal.org.
merzikain's picture

I've been trying to get this View page to build based on an nid I'm passing in the url.

Seems like pretty simple stuff but for some reason it is defying my efforts at every turn.

I had it working using the title but there is a chance of duplicate titles so I have to use nid (like I should have from the start).

So I have a url set as: articles/[article title]/[nid]

In my view I have the path set as: articles/%/%

I have arguments set as:
Node: Title (providing default value using php code: $args[1] = arg(1); return $args;)
Node: Nid (providing default value using php code: $args[2] = arg(2); return $args;)

I've been reading different things about using arguments and it just doesn't make sense (what I'm reading and what I'm doing wrong) so I'm here to ask the experts to enlighten me because I'm obviously doing something stupid here.

The article title isn't doing anything at this point but it is a kind of wildcard since it's between the static articles/ and /nid. Not sure if maybe that's what I'm doing wrong. I've been looking at the query when it builds and the where clause keeps showing node.nid = 0 instead of any of the valid values I've given it. It also shows node.title = [article title] just fine so I really have no idea why it's not accepting the nid.

Any idea what I've done wrong?

Comments

why are you providing default

Scott Reynolds's picture

why are you providing default arguments with php code. your url will line up with what you want.

I'm not real sure what my

merzikain's picture

I'm not real sure what my thinking was, I guess I was thinking that's how I'd force it to show the right one. Now that I think about it, that's kinda ridiculous so I'll change it to display nothing instead.

I've been messing with it some more and now it looks like it's trying to grab the values out of order. It's setting node title as arg(0) and nid as 0 since arg(1) is the node title and doesn't convert to an int (I'm assuming). So what do I need to do to get the right values?

I added a Global:Null

merzikain's picture

I added a Global:Null argument above the other two so that my Argument list looks like:

Global: Null
Node: Title
Node: Nid

When testing the view with "articles/my-article/1" the query gets built properly and shows the right article. However when I save it and test it on the site I get page not found.

Ok so I went back to using a

merzikain's picture

Ok so I went back to using a default argument like I did before because I recalled that I was setting the argument as: return arg(1); when I was using the title to get my list. That worked for me with the title so I tried it with the nid.

Here's where it gets strange. The page display doesn't work but the block display I setup earlier does when I set the Node: Nid argument to have a default argument of: return arg(2);

Why is it working for one but not the other?

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: