There are probably several ways to do this, but since views is definitely involved and Views support seems better than most, I will ask here first.

I have several content types displayed in view blocks. The views display node titles of nodes that have a reference to the current node. (reviews, plots, rumors, news etc) ex: http://www.batman-trailer.com/movies/dark-knight

This works great, but as you can see I have an add a review link (or plot or rumor etc.) in each block views footer and empty text. The link is direct to the add content page for that specific content type. Works great, but I would like the link to go to that page and populate the node reference field with the id of the node the views block and entire page was about, so members don't have look through all the nodes or guess.

The id is already available because in using it in the view. I was thinking about the prepopulate module to do this but how do I write the link. Especially since the nid isn't static.

Thanks in advance, Ive seen some issues that are somewhat similar but not close enough, and this has got to be more common than it seems.

Comments

dawehner’s picture

<?php
$nid = arg(1);
l(t('Add articel'), 'node/add/article', array('query' => 'edit[field_prepopulate][0][nid]='. $nid));

I don't really see the views question in it.

kevster111’s picture

Im not really sure where I should be asking this actually, I felt views because Im sending the link from a view block in the footer and empty text, and I cant get the footer text to display in the block when using php. Plus everything works if I send the url directly without a variable.

ex: if I put this in the url, everything works fine.
http://www.batman-trailer.com/node/add/review?edit[field_nodereference][...

If I use the php code in the footer and the empty text, the link isn't shown in the block, This is the exact code I used I may have put it in wrong. I have the input filter for php as well.

$nid = arg(1);
l(t('Add review'), 'node/add/review', array('query' => 'edit[field_reference][0][nid]='. $nid));
kevster111’s picture

Wow I feel dumb, I just copied code and didn't really look. I forgot a print statement and the field_reference should be field_nodereference

Ill leave this up for anyone else, Plus anyone have any other ways of doing this.

$nid = arg(1);
print l(t('Add review'), 'node/add/review', array('query' => 'edit[field_nodereference][0][nid]='. $nid));

Thanks for the help dereine, it was really getting to me.

dawehner’s picture

Status: Active » Fixed

Anyway this should be marked as fixed.

You can always search the issue via search.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.