displaying multiple Views within Views with argument

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
freeform.steph's picture

Goal: to display multiple views within a view such that each row of the primary view passes a variable to the embedded views so that all of the content for 2 different content types can be displayed based on their relationship with the contents of the primary view.

Table display of the primary view would look something like:

[view1: row1 content [view2: content related to row1] [view3: content related to row1] ]
[view1: row2 content [view2: content related to row2] [view3: content related to row2] ]

Module used:
Views Custom Field: http://drupal.org/project/views_customfield

Function used:
views_embed_view(viewname,display_id,arguments)

Here are the instructions to get this working:

1) create 1 view with a display of type block for each of your embedded views. Set the argument to the desired variable you would like to receive from the primary view (such as node ID)

2) create the primary view with a single page display and include the following fields:
- create a hidden field for node id, or whichever variable you wish to pass to the secondary view from step 1
- create a field of the type "customview: PHP code" and enter the following code:

<?php
$args
= $data->argument_variable_name_id;
print
views_embed_view('view_name', 'display id',$args);
?>

TIPS:

1) To determine the names of the available variables accessible to your field, add the following in your customview and preview your display for the output

<?php
print_r
($data);
?>

2) View name should be the name of the view created in step 1, the computer-friendly name of each view is listed on the List Views page

3) Display id is the id, NOT the name, of the display created for the secondary view. You can get the ID by rolling-over the display's tab in the view and looking at the url at the bottom of your browser. The end of the url should have something like "#view-tab-block_1", from this you can extract the id from the end, "block_1".

4) After some troubleshooting it was determined that the secondary displays must be in a separate view from the primary display, and not simply additional displays within the same view - output will return nothing if you do this.

Comments

Very interesting!

Maedi's picture

Very interesting!

Thanks!

t_durden's picture

worked great! much appreciated!

un pb aux cours d'utilisation de ce script

ali_bm's picture

svp j'ai un pb
1/ view etablissement courant ( view principal )
2/ view liste materiel par etablissement (view secondaire )
pour afficher la liste materiel (par etablissement et par etablissement courant) j'ai utilisé les deux views mais l'affichage se determine dans une liste box l'un aprés l'autre
----> Merci de m'aider

le pb c'est que l'affichage

ali_bm's picture

le pb c'est que l'affichage dans liste box s'affiche dans une seul ligne et pas dans des lignes différent

Je ne suis pas sure si je

freeform.steph's picture

Je ne suis pas sure si je comprend, avez-vous choisi le mode de display "table"? ou bien ajouter du CSS dans le stylesheet do votre theme? J'ai peut-être besoin de plus de détail pour comprendre ce que vous demandez.

For the record there is now a

tizzo's picture

For the record there is now a Views Field View module which does this specifically and also sports an experimental query aggregation feature which turns the list of lists into 2 queries rather than running the main query and then an additional one for each and every row.

[edit: At the time of writing that experimental feature is only available in HEAD and not in the current beta release (beta1)]

Thanks for posting - I will

freeform.steph's picture

Thanks for posting - I will check this out!

svp je veut une solution de

ali_bm's picture

svp je veut une solution de code php argument
je veut juste afficher le materiel de l'utilisateur courant et de l'etablissement courant .
condition etab_utilisateurcourant=etab_matriel
ya til qq peut m'aider
Merci ;

Il me prendrait une éternité

freeform.steph's picture

Il me prendrait une éternité pour répondre en Français, mais si vous ne me comprenez pas, laissez-moi savoir et j'essayerai.

If I understand:
- Users can create documents that are related to an organization (node reference to organization content type)
- When logged-in user visits an organization, they should see only a list of the documents that they have posted to this organization

Set the relationship for the node reference and set your argument to "provide default argument" NODE ID from URL, validated to node of type organization and be sure to choose "use relationship". Use a filter to limit the content to the logged-in user.

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: