I have successfully created a view that shows the child fields based on the parent nid passed through the view, by setting up the parent node id node relativity relationship, and then using that relationship on the node id as an argument (see set #4 here: http://drupal.org/node/82415#comment-444495). This works great!

What I need now is to provide a "create" link for the empty text of this view. I tried this, but it returns the link without the parent nid at the end.

<?php 
global $current_view;
$current_view->args[0]=$node->nid;
print('<a href="node/add/prm-starting-units/parent/' . $node->nid . '">[create]</a>');
?>

I also tried what seemed like another logical choice, but again no nid at the end of the url.

<?php 
print('<a href="node/add/prm-starting-units/parent/' . $parent->nid . '">[create]</a>');
?>

Can someone please steer me in the right direction?

Comments

oda’s picture

I think that the best way to create a view that list child/parent fields is to follow the instructions that i gave here: http://drupal.org/node/494066#comment-2452102

Then you can use the relationship in the argument.

Anyway... You can create a link to add a new child add the following header (or footer) to your view:

<?php
  $view = views_get_current_view();
  $nid=$view->args[0];
?>
<a href="/node/add/[NODE_TYPE]/parent/<?php echo $nid; ?>?destination=[VIEW_PATH]%2F<?php echo $nid; ?>">New child</a>
cindyr’s picture

Status: Active » Closed (fixed)

Thanks!