This might be a dumb question, but I don't get it.

I need to display the child nodes' content (or parts of) inside a parent's page. In my setting, for example, the parent document has several related document, all of which are CCK-defined. For instance, a course definition has several such kids which are of different types: syllabus, links, tests, etc. I need the course definition to display parts of the related documents, and not only links to them, as does Node relativity by default.

The simplest solution would be to design a view (with the View module) that filters the children nodes according parent ID, and set the parent ID is the current node id. This way I could display, for example, the title and the summary field of each documents inside the main view. This in effect would create a dynamic compound document. (In fact, my whole project relies heavily on that feature)

However, I can't figure out how to do that. Views seems to have all the required mechanisms in place (including displaying a *no document found* message when no child node is present), except for acknowledging the parent's node ID in the filter. I must be missing something somewhere. I know I could spend a few days (i'm optimistic) figuring out the inner working of the code and write my own *view*, but i'd rather use the modules in place... as it would be much easier to maintain.

Does anyone has an idea how to that?

Cheers,

-) efolia (-

P.S.: This module is awesome... and it's going to get even more awesome as it evolves.

CommentFileSizeAuthor
#3 relativity_views.inc.patch833 bytesefolia

Comments

darius’s picture

efolia’s picture

Thaks for your answer.

Yes I did (this is the thread that started the whole project I'm doing, actually).
There's a few critical bugs in relativity_view.inc that prevents it from working at all. I'll work on that today and I'll be back with a patch (I'm not too fluent in the inner workings of module interactions, so that slows me down).

In the mean time, even if it did work, it still would be missing, from my purpose perspective, a critical part, since parent nodes have to be referenced explicitly. My point is that in order to enable a dynamic compound document type -- where document A displays (and links to) the content of children documents B, C and D, for example -- the view that does this has to default the patent node filter to (or have an option to filter by) the current document/node as parent. The reason is that the parent document cannot be expected to be unique at the top of the relativity hierarchy. As soon as I'm done with debugging, I'll figure out a way to add this option to the filter. It shouldn't be much work, actually, since the code is clear and well written. I'll be back, hopefully with all that. 8-)

-) efolia (-

efolia’s picture

StatusFileSize
new833 bytes

Here's a patch for the two bugs that prevented the views module from working correctly.

-) efolia (-

efolia’s picture

I forgot to mention that I owe it to Merlin for locating the *parent_nid* bug. Thanks a million!

-) efolia (-

darius’s picture

Committed the patch, thanks. Keep up the good work.

oprior’s picture

Sorry, but I'm a real newbie at installing patches and just can't get this to work.

How far off is this from being added to the general release?

I'm asking because if someone could do this it would save me, I'm only on Mac OSX Panther so XCode won't work for me (requires Tiger) and I get way too many errors that I don't really understand when I'm trying to install the patches via Terminal.

Maybe if someone could give explicit terminal instructions on installing these patches that would help, sorry to be such a pain.

darius’s picture

The patch in this issue has already been applied (download the latest CVS version: http://ftp.osuosl.org/pub/drupal/files/projects/relativity-cvs.tar.gz). As for additional improvements, it depends on people contributing new code.

Darius

patchak’s picture

Hi,

I installed node relativity CVS and views 1.4 on a drupal 4.7.5 fresh install, and when I try to build a query in views I get this error:

user warning: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN (''))' at line 1 query: SELECT count(node.nid) FROM node node LEFT JOIN relativity relativity ON node.nid = relativity.nid WHERE (relativity.parent_nid AND '') AND (. IN ('')) in /homepages/43/d184490741/htdocs/www/guitare/includes/database.mysql.inc on line 121.

I tried with the 4.7 version of relativity (4.7-2) and with CVS as well, same error in both cases.

Could you tell me with which versions of relativity and views you can make it work?

Thanks

darius’s picture

The CVS version is the same as 5.x-1.x-dev, so it works on Drupal 5.0
For Drupal 4.7, use version 4.7.x-2.x-dev.

I haven't tested the views and relativity for a while, but I do recall it working on Drupal 4.7. The error is produced by the views module, but I don't have time to investigate it for now. If you can track down the cause, I will be more likely to fix it soon.

Darius

patchak’s picture

Hi,

It's actually a bug in views, that you have to select a node type in the filter settings. If you leave it empty (not selected) you get this error. I think merlinofchaos is aware of the bug, so all is good.

BTW it seems to work, but here's another question.

is it possible to get a view that grabds the ID of the parent node from the URL and the displays it's childs, using arguments??

Thanks

JohnG-1’s picture

#10 "exposing children to views" ;)

if it's not illegal, I'm interested in this question too.

I'm thinking of using CCK embedded view to display $this_node's children in a table (showing node_title and CCK 'metadata' columns liked time_created, etc).

I use the 'Relativity: Parent Title' option in the list of View Fields quite alot, but there's nothing for the children.

I assume we need a 'Relativity: Children Title' field (generated by relativity_views.inc) or is ther some trick with build/views that I've missed ?

patchak’s picture

well to display node children, I think you need to select node relativity parent as an argument. Selecting the right parentwill give you the children automatically!

hope this helps.

Patchak

JohnG-1’s picture

ah! yes of course! thanks Patchak .... I got this to work:

1. create content types (if necessary) at admin/content/types:
+ create a CCK node-type called 'Ntype1'
+ create a CCK node-type called 'Ntype2' and add some fields if you like :)

2. configure node relativity (if necessary) at admin/settings/relativity:
+ set Ntype1 as parent to Ntype2
+ set Ntype2 as 'one or more' parents

3. populate some nodes (if necessary) at node/add (create content):
+ create an Ntype1 called 'Parent_test_1'
+ add a Ntype2 using the 'add new Ntype2' link on the 'Parent_test_1' node, call it 'Child_test_1A'
+ add another Ntype2 using the 'add new Ntype2' link on the 'Parent_test_1' node, call it 'Child_test_1B'

4. create the View at admin/build/views:
+ create a View called 'View_Ntype2'
+ set Page View: Provide Page View -> Yes
+ set Page View: View Type -> Table
+ add filter: 'Node: Type' and set it to 'Ntype2'.
+ add field: 'Node: Title' and any other Ntype2 fields you like.
+ add argument: 'Relativity: Parent Node ID' and set it to 'Display all values.

5. embed the view in the PHPtemplate at (filesystem) drupal/themes/$yourPHPtheme/node-Ntype1.tpl.php:
+ embed View_Ntype2 into the PHPtemplate for Ntype1 by inserting the following code into node-Ntype1.tpl.php:

    <?php
         global $current_view;
         $current_view->args[0]=$node->nid;

         $view1 = views_get_view('View_Ntype2');

         print t("<br />"); 
         print '<h2>' . t($node->title . ' Ntype2 Children:') . '</h2>';   
         print views_build_view('embed', $view1, $current_view->args, false, false);  
     ?>

This should display a table, showing all relevant Ntype2-child-nodes, in the body of Ntype1-parent-nodes.

Another variation, which shows 2 distinct views (View_Ntype2 and View_Ntype3) in the body of Ntype1 nodes uses this code in node-Ntype1.tpl.php:

    <?php
         global $current_view;
         $current_view->args[0]=$node->nid;

         $view1 = views_get_view('View_Ntype2');
         $view2 = views_get_view('View_Ntype3');

         print t("<br />"); 
         print '<h2>' . t($node->title . ' Ntype2 Children:') . '</h2>';   
         print views_build_view('embed', $view1, $current_view->args, false, false);

         print t("<br />"); 
         print '<h2>' . t($node->title . ' Ntype3 Children:') . '</h2>';   
         print views_build_view('embed', $view2, $current_view->args, false, false);  

     ?>

I feel a handbook page coming on ... any comments welcome :)

patchak’s picture

Really cool tips about how to insert a view directly at the theme level...I was wondering about that for a project, and the best I could find was to publish the view as a block in the "content" region, which of couse is not always the ideal way to do.

Could you explain how to get the arguments from the URL, for example if I would like to insert a view in the users profile page at user/UID, how would I do it??

Thanks

JohnG-1’s picture

not sure :P TBH I don't understand why or how $args work ... the above is just a hack :)

First off I would try keeping the $current_view->args[0]=$node->nid; in the PHPtemplate and experiment with the various preset User argument_handlers in Views :
User: UID Authored or Commented (HB "The User ID argument allows users to filter a to nodes authored or commented on the specified user ID.")
User: UID is Author (HB "The User ID argument allows users to filter to nodes authored by the specified user ID.")
User: Username is Author (HB undocumented)

(don't forget to set the argument to 'Display All Results' ;)

If none of these return any results,
try changing the first argument(?) $args[0]= in the PHPtemplate from node->nid
to node->uid: ie $current_view->args[0]=$node->uid;
or user->uid: ie $current_view->args[0]=$user->uid;

good luck and please let us know if you discover any useful tricks :)

summit’s picture

Subscribing, greetings, Martijn

spencersundell’s picture

Version: master » 5.x-2.x-dev

Hello --

The procedural above was immensely helpful -- thank you, JohnG!

I was also able to format my view using ConTemplate. This eliminated unnecessary (and invalid) fieldsets and legends.

However, in my case each of the child nodes still have the node title (linked inside an H2) as a header element and links to related taxonomy categories as a footer element. This is totally borking my layout and design. (Also my SEO.)

For the life of me (and yes, I'm fresh to Drupal [hangs head in embarrasment]) I cannot figure out how to be rid of the infernal things. I just want the child element formatted the way I want it -- no H* tags, no fieldsets and legends, no links unless I put them there. It really seems like it must be utterly simple to do this...so I know I must be missing something fairly obvious.

Perchance does anyone have any suggestions along these lines? I've been parsing the documentation for a week solid and it's really not helping me much in this context.

(...alas...if only I could simply repeat field groups in CCK like I can fields...boo hoo...)

Kind regards...

CoolDreamZ’s picture

Very useful thread, subscribing....

mr_dimsum’s picture

Is there a particular method to display only certain fields under the parent node with the code provided above? For example, I only want the image thumbnail and title of the child node to appear under the parent node, so it kind of acts as a teaser to the full article.

mr_dimsum’s picture

Just wanted to let everybody know that I have gotten this to work with EASE. Except, not with Node Relativity. Rather, I used Node Heirarchy. The developer (Ronan) was kind enough to give me some rapid fast responses and I got it up in no time. Unfortunately, it's a bit of a manual process as I cannot "auto-attach" the child display into the parent node through automation.

You can view the thread here. If anybody knows the code to automate it, please contribute to the post here: http://drupal.org/node/200846#comment-784130

By the way, by using Node Hierarchy, I am able to display ANYTHING from a child node on the parent page pretty much!

spjsche’s picture

subscribing to this excellent module.

Thanks

andb’s picture

mr_dimsum, If I understand hat you are looking for, this is easily solved this with views and made nicer with contemplate.

1) I suggest that you make a new module based on the Views Grid Bonus View. Remove the table logic, the cycling logic which builds the TR fields, and change the TD's to divs. Then you can make view based on this new module, which outputs into divs, which are much easier to layout than tables. It will only output the fields that are selected in "fields", just like a list or table or grid. Don't forget to include the Relativity: Parent ID field... Using CSS then define the div behavior so the view will look nice. Grids, vertical or horizontal lists, making the view like this allows it all.

2) In the Node Relativity Module config, change the display view used for each child of the parent to be your newly made view(s).

2) In the modified contemplate body of the parent put print $node->content['relativity_children']['#value'] where you want the child list to show. This will embed your newly made view in your parent page, where you want, as you want.

Ive found this method to allow incredibly fast and easy customization of the display of children in a teaser-like style on the parent page.

BettyJJ’s picture

The code #13 is very helpful. Thank you!
However, if I use it, the link operations on the parent node page, such as "create new child node", "attach existing child node", "remove child node" are gone. How can I add these links back?

summit’s picture

Subscribing,
greetings,
Martijn

xjm’s picture

Tracking.

milos.kroulik’s picture

Version: 5.x-2.x-dev » 6.x-1.1

I don't see any Argument for Parent Node ID in Views 2. Is it already implemented? It seems critical to me. I added Node Relativity:Parent Node ID Relationship.

cindyr’s picture

@JohnG #13 - Thank You!