In Drupal, how can I include one node in another?
Let's say I have two content types, Proposals and Actions. A Proposal would contain several Actions, but Actions should also be viewable independ开发者_高级运维ently as well. Each would contain several text fields and links.
Should both Proposals and Actions be Nodes? How would I go about doing this?
Inherently there is no parent / child relationship in drupal. You can build such things using the CCK's node reference and some creative views.
There are a number of ways of doing this, as with most things in Drupal but if it was me, I'd do this:
- Build node relationship in CCK
- Load the "child" i.e. related node with node_load() in the template file
- Pull the bit you want out of the newly loaded node and print it out in the "parent" node
Edit: yes they should both be nodes.
If you use this method, then once it is set up you will have to go into your proposals and choose which actions you want to be "contained" (i.e. linked to).
Then to print them out you will want some code similar to
<?php
$actions = $node->field_name_of_your_actions_link_field;
foreach($actions as $action){
$anAction = node_load($action[nid]);
$output .= $anAction->the_bit_you_need_to_get[0][content];
}
?>
Of course the variable names will be different but hopefully this will point you in the right direction
Try to use Views block display. You need create a block display for a view that shows all(or how much you need of them) Actions nodes associated with the corresponding Proposal node (You will need to set view argument to something like that: Nid - Provide default argument - Node ID from URL). And then attach this block to the pages that represent your proposals pages.
Have you looked into the module Views? It is extremely robust and lets you display nearly anything.
If you do use views you'd do something similar to this: Two content types, and a taxonomy vocabulary to tie the actions to proposals (therefore, put the term reference field on the actions content type).
Then you would create a page view which would filter by content type proposal. You'd be able to add all the fields from proposal, and order them and do your css to have them display how you want.
Then, you would have another view, this time a block, and this would list your Actions out so you'd filter by that content type. Then you would add a contextual filter to get the taxonomy of the node you have loaded. Once you display this block on the proposal pages, it should show the links for their actions.
I think this basically covers it, it's a little hard to explain without actually doing so if you run into anything let me know.
Views is great. It's a little intimidating but once you get the hang of it quite easy to use. My apologies if you already knew of that and I missed something about your requirements.
精彩评论