Closed (fixed)
Project:
Views (for Drupal 7)
Version:
5.x-1.6-beta5
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
19 Jun 2007 at 20:07 UTC
Updated:
4 Jul 2007 at 18:17 UTC
I'm trying to pass the title of the current node as an argument for a view block. I have the following specified in the argument text field:
$node = node_load(array('nid' => $nid));
$args[0] = $node->title;
return $args;
But it doesn't seem to work. Help! If I hard code the title like this
$node = node_load(array('nid' => $nid));
$args[0] = "Title Here";
return $args;
I get what I expect, so I'm guessing the first line is wrong somehow. I'm clueless as to what I need to change, though. Anyone want to shed some light on this issue for me?
Comments
Comment #1
merlinofchaos commentedThe problem is likely that $nid is undefined. Where are you getting the $nid?
Comment #2
prattboy commentedJust putting it into the arguments field... so... uhm... nowhere...
...so I guess the question is then how do I get the node's title?
Comment #3
merlinofchaos commentedTHat's the wrong question.
The question should be...what node? You're making the assumption that $nid will be populated. But it isn't.
Are you trying to do this where the block will be displaying on the node/XXX page? If so, then adding $nid = arg(1) will do it. But if it's some other esoteric place you'll have to figure out how to figure out what node you're working on.
Comment #4
prattboy commentedIt's being displayed on a node whose URL ends in node/7, but I'm hoping it to pull the title of the node, which is something like the string "Category Name"
Comment #5
nevets commentedSee comment #3 from merlinofchaos, using his example your code would read
which should do the trick if viewing pages with a path of the form "node/NNN", where NNN is a number
Comment #6
merlinofchaos commentedI should add that there isn't very much Views can do with an argument that is a title, since in general it uses arguments to try and do filtering. What are you trying to accomplish there? My best guess is that, unless you are sure you know what you're doing there, what you really want is to give Views the nid as the argument, and use %1 in the 'title' field for the argument.
Comment #7
prattboy commentedThanks all! Seems to work well.
This is definitely a specialized case, and I can't think of another situation where I'd want to pass the actual title name to a view.
I'm in a situation where I needed a description page for each category term that is created. Additionally, I needed revision control over that description. The taxonomy module in the Drupal core allows you to create a description, but doesn't give any one any editing control unless they have administrative access to the taxonomy module. In my situation, that wasn't going to cut it.
So what I did is set up the NAT module (http://drupal.org/project/nat) to create a new term every time a node of a specified content type is created. The term is the same as the title name of the created node... and since I can pass the title name to the views module, I can display any pages tagged with that term by passing the title name of the currently viewed page to the Taxonomy: Term Name argument. Additionally, since an actual node is created and not a category listing, I gain the ability to assign permissions to edit and to have revision control.
So it's highly specialized, convoluted, and there's probably an easier way. But, for now, it works.
Comment #8
(not verified) commented