I'd like my parent view to be able to receive an argument and pass it through to a child view. Is there a way to do this? Thanks.

Comments

gthing’s picture

I used the views_php module to add a php field.

In the setup code I used:
$static = $view->args[0];

Assuming you have no actual arguments on the view, [0] will be the first argument.

Then in the output code I used:
<?php echo $static; ?>

I hid the field from display and removed the label. Seems to be working okay.

Would this be the best way to do it or is there a better way?

scottrigby’s picture

Title: Pass through argument from parent view? » Is there a better way to get a parent's argument on a child view?

Updating title for clarity.

damiankloip’s picture

Status: Active » Fixed

You should be able to use the magic !1/%1 (etc..) tokens to do this. You may need the dev versions.

dalearyous’s picture

#3

can you clarify? i am having issues using the tokens listed in the replacement patterns.

damiankloip’s picture

What are you trying to get? are you using the dev version?

dalearyous’s picture

i have tried dev version and the recommended version. both do the same thing.

i am trying to pass two fields into the child view so that the child view shows the correct data. i have been playing around with it and it seems only one field actually works (in my case "Project Name").

i wrote up a question and posted it here: http://drupal.org/node/1732732

since then, i can get it to do what i want except it, for no apparent reason, excludes certain account names.

dalearyous’s picture

FIXED IT! this may deserve a bug report. there is something odd going on when passing in your contextual filter. to get around it this is what i did:

go to your child view and add a global php field. in the output code area add this: (you will delete this field later, for debug purposes)

print_r($data);

find the field you are trying to pass through and essentially get the raw value, in my case it was this:
$data->field_field_project_name_s['0']['raw']['value'];

now, go to your parent view (i am assuming you have contextual fields set already) and add a global php field with this output code with what we just found out:

print_r($data->field_field_project_name_s['0']['raw']['value']);

save it, drag the field to the top of the order (so it can be used in the views field view). open up your views field view and instead of using the tokens they are suggesting, use the one that correlates to the global php field we just created. in my case:
[%php_2]

and boom, the accounts (project names) that weren't matching up at all are all now working perfectly.

i will write a more concise guide with everything i did, including contextual filters and post back here with link.
http://blog.cvrc.virginia.edu/?q=drupal-guides

jamix’s picture

@damiankloip: Thanks, switching to the dev version solved my problem with the magic !1 token not working properly.

Status: Fixed » Closed (fixed)

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