I have a site where I am using node references and then view references to import related node lists (via a view) into nodes.

I'm passing the %nid as a reference and I managed to get the first view reference working by using the following suggested PHP argument handling code:

if ($type == 'block' && arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
//$node = node_load($nid);
$args[] = $nid;
}
return $args;

This works great, but if I try to add a second view reference to the same type of CCK node, things get a little strange. First, the $node->field for that view reference never gets created (or doesn't show up in contemplate) unless you update one of the nodes of that CCK type. It does create the new node->content handle though. Once you update one of those nodes, and it then appears in contemplate, you can insert it in your node template to display. However, it then inserts a completely different view that wasn't selected and the referenced nodes don't seem to be referenced anymore.

I am guessing that somewhere between handling the argument for the first inserted view reference and the second view reference, something is changing with the arg and as a result the second view reference isn't grabbing the right view. I know that the arg is an URL reference, so maybe I just need to pass the second arg in a different format? I would pass both view references as one field, but I need to style them separately in different areas of the node.

Does this make sense? Has anyone else tried to have two separate view reference fields (with the same %nid / node reference arguments) attached to a CCK node?

Thanks in advance.

Comments

inforeto’s picture

Yes, well, i don't know what exactly you are trying to do but you can insert multiple views in contemplate.
Just be sure you pass the right argument to them.
If you use the php functions to insert views you can use an array variable to pass the argument values, and this overrides the default arguments as taken from the path.

$my_args = array();
$my_args[0] = $nid;
$my_view = views_get_view('my_view_name');
$my_fields = views_build_view('embed', $my_view, $my_args, FALSE, 1);
$field1 = $my_fields[0];
$field2 = $my_fields[1];
$field3 = $my_fields[2];

As for contemplate, the $node only contains the values of the current node.
You can use $other_node = node_load($some_nid); to load other nodes, with all their values.

You can also do node_load() in a theme views function, to avoid having too many cck fields in the view.

eurekaloop’s picture

Thanks! I figured there had to be an easier way to do this...

My problem was that the first view was showing up in the contemplate with both the $node->field and $node->content reference that I could use, but the second view wasn't showing up with the $node->field reference, only the $node->content reference, which printed out nothing.

Anyways, this makes things easier as I don't have to mess around with finding the right call from contemplate. I can just insert the script you gave me where I need it.
:)

Thanks again.

eurekaloop’s picture

For anyone else looking for this solution, I should also mention that I swapped out the word 'embed' with 'block' to get my custom table view to show up instead of the entire nodes.

Thanks again.

socialnicheguru’s picture

chris

http://SocialNicheGuru.com
Delivering inSITE(TM), we empower you to deliver the right product and the right message to the right NICHE at the right time across all product, marketing, and sales channels.