Hi!

First off, thanks for a great module!

I've been struggling with theming individual nodes in a zone. Say that I have a zone 'bottom'. In that zone I want the referenced nodes to be displayed side by side (or only one depending on other cck fields) in a two column fasion like this:

node | node
node | node
n o d e
node | node
n o d e

I have 20 fields (Field value: Headlines [0 - 19]) in that zone. They all get stacked ontop of each other and they all have the classes "field-item odd".
I would want to be able to change that "odd" class to say for example "odd", "even" or "stretch" depending on what the current, next and previous node was.

My scenario is like this. I have nodes (story) that can have a cck image field enabled and if it is, the node should span over two columns. If the first node doesn't have an image and the next node doesn't either then I want to set the first one to "even" and the next one to "odd" so that they form "node | node". But if the second one contains that image then the first node should be stretched on one row and also the second one. Then I would continue this check for all the nodes.

I guess this can't be done with hooks? Where would be the best place to implement this in the code? Any ideas are welcome!

Thanks!

Tobias

Comments

bengtan’s picture

Status: Active » Closed (works as designed)

Ouch, your example scenario with nodes that span one or two columns depending on what's before and after it is ... tricky.

I don't this sort of complicated logic is possible, or even desirable, with Composite Layout. It would require Composite Layout to know too much about specific situations, and is not useful for the general case.

I'd go so far as to suggest not using Composite Layout at all. You can use node templates (ie. .tpl.php files) and custom PHP code in the *_preprocess_node() theme hook and that would give you the flexibility you'd require.

drupalftw’s picture

Hi, thanks for the reply. Forgot about this question. But I fixed it like this. There is obviously overhead in this solution

I have a module where I use hook_nodeapi() and in $op 'view' (if node is composite) I call a function and pass the $node by reference and the code for that function:

<?php
function layout_zone_bottom(&$node) {
  $field_headlines = array();
  $nodes = array();
  foreach ($node->composite_references as $key => $field_headline) {
    if (substr($key, 0, 16) === 'field_headlines-') {
      if ($field_headline['zone'] == 'bottom') {
        $field_headlines[$field_headline['delta']] = $field_headline;
      }
    }
  }
  ksort($field_headlines);
  foreach ($field_headlines as $delta => $field_headline) {
    $obj = db_fetch_object(db_query('SELECT ct_story.nid, ct_story.field_show_teaser_value AS image, cf_headlines.delta FROM 
    							{content_field_headlines} AS cf_headlines LEFT JOIN 
    							{content_type_story} AS ct_story ON cf_headlines.field_headlines_nid = ct_story.nid 
    							WHERE cf_headlines.delta = %d', $delta));
    if (is_object($obj)) {
      $nodes[] = $obj;
    }
  }
  $column_count = 0;
  $image_count = 0;
  $num_nodes = count($nodes);
  for ($i = 0; $i < $num_nodes; $i++) {
    if ($nodes[$i]->image) {
      $class = 'stretch';
      $column_count = 0;
      $class .= ($image_count % 2 == 0) ? ' zone-image-left' : ' zone-image-right'; 
      $image_count++;
    } else {
      if ((isset($nodes[$i+1]) && !$nodes[$i+1]->image) && !$column_count) {
        $class = 'left';
      } else if ($column_count) {
        $class = 'right';
      } else {
        $class = 'stretch';
      }
      $column_count++;
    }
    $node->composite_references['field_headlines-' . $nodes[$i]->delta]['class'] = $class;
    if ($column_count == 2) {
      $column_count = 0;
    } 
  }  
}
?>

and now I can theme it with CSS.