Hi all.
While trying to form a list with nodes' fields using forward and reverse references I stumbled upon some obstacles.

What I wanted:
One list that consists of nodes (or some specific fields of the nodes) which refer to the current node and nodes (or some fields of the nodes) that the current node refers to. So if we have these kinds of relationships ...
node_2 -> node_1 -> node_0
... for the node_0 I want node_1 to be in the list, for the node_1 I want node_2 and node_0 to be in the list, for the node_2 I want node_1 to be in the list.

What I did:
1. Created some content type with node reference field & a couple of other fields.
2. Created a view with block and attachment displays.
3. To the block display I added Content: Node reference relationship and (Node reference) Node: Nid as argument specifying that Node ID from URL should be provided as default argument. Added some fields. So this display should show all nodes (or fields of the nodes) which refer to the current node.
4. To the attachment display I added Node: Nid as argument overriding default value and again specifying that Node ID from URL should be provided as default argument. Overriding defaults added some fields specifying Node reference as relationship for them. Attached this display to block display. So this display should show all nodes/fields of the nodes that the current node refers to.
5. Created 3 nodes with the relationship shown above (node_2 -> node_1 -> node_0).
6. Added the block with the created view to some area.

Result:
In the node_1 both the fields from the node_2 & the fields from the node_0 are shown.
In the node_0 the fields from the node_1 are shown.
(!) In the node_2 the fields from the node_1 are not shown.
So it seems that if the block display of the view contains nothing, the attachment display is disregarded. (Is this by design?)
The main question: is there a way to combine the output of the group of several view displays (or views) in one block so that this block will be displayed when at least one display of this group of views have some data to show?
Sub-question: is it possible to format the output of several views in one way (e.g. placing every item from several views in the same ul)?
Found this http://sethsandler.com/software/drupal-6-creating-activity-stream-views-... in http://drupal.org/node/748844 but it seems that this approach is not flexible at all.

Also if the block display contains some data & the attachment display does not, the attachment display nevertheless contains some needless markup (ul li).

Comments

merlinofchaos’s picture

The work around for this is to ensure that you have something (even if it is just a blank space) in the empty text.

looney_toons’s picture

Thanks. What about needless markup in attachment display if it has no data?

I noticed some strange behavior. Considering that the view/display A is constructed like in clause 3 & the view/display B is constructed like in clause 4 from my previous message, the following is observed:
1. If the view has block display (A) with attachment display (B) & the block display is placed in some area, the attachment display (B) contains needless markup if it has no data & this display is not considered empty (see the code below).
2. If the view has two block displays (A & B) & these displays are placed in some area, the block display B contains needless markup if it is empty & is not considered empty.
3. If there're two views (A & B) each with one block display & they are printed using views_embed_view() the view B contains needless markup & is not considered empty.

So it seems it has something to do with the way these views/displays "B" were constructed:
4. To the attachment display I added Node: Nid as argument overriding default value and again specifying that Node ID from URL should be provided as default argument. Overriding defaults added some fields specifying Node reference as relationship for them. Attached this display to block display. So this display should show all nodes/fields of the nodes that the current node refers to.

All in all right now it seems there's no way to show some title for two views/displays in case at least one of them is not empty (this title in the following example is shown always).

 //in template.php
function theme_embed_view($viewname,$display = NULL) {
	$args = func_get_args();
		array_shift($args); // remove $name
		if (count($args)) {
			array_shift($args); // remove $display_id
		}

	$view = views_get_view($viewname);
	$output = $view->preview($display,$args);
	// At least in $view->result is the result.
	if ($view->result) {
		return $output;
	}
}
 //in node-msg.tpl.php
	$view_name = 'msg_related';
	if ( (theme_embed_view( $view_name, 'block_1' ) != '') || (theme_embed_view( $view_name, 'attachment_1' ) != '') ) : //always true because of (theme_embed_view( $view_name, 'attachment_1' ) != '') 

<h4>Related:</h4>

	print views_embed_view($view_name, 'block_1' );
	endif; 
looney_toons’s picture

The work around for this is to ensure that you have something (even if it is just a blank space) in the empty text.
Forgot to add that this workaround doesn't help much, because if I insert blank space into Empty text item in the view that is constructed like in clauses 3,4 from my 1st message, this view appears on every node page that exists if at least one reference from some node to the other is present, also this view has the markup of the Attachment section up until <div class="item-list"><ul><li> but this section has no data.

dawehner’s picture

If you have empty output like this you might forgot a filter on the view, for example if you display
user pictures you should filter whether the user has a picture.

looney_toons’s picture

The only filter I have in the view is Node: Published Yes and I'm showing only Date & Title fields (both are present in every node).

Letharion’s picture

@looney_toons
If I understand dereine right, he suggests that you may need an additional filter. Could you add a filter for node: type, or something else that will distinguish the right nodes?

Letharion’s picture

Status: Active » Postponed (maintainer needs more info)
esmerel’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

No updates for 30 days