Hi,

hi - this questions regards displaying specific CCK values in a custom calendar view. Because the Week View is integral to my usage, this is build in 4.7

it seems there's not much theming information for CCK output via Calenar. None of the standard node-content_example.tpl.php, or field-field_my_field.tpl.php solutions work (unless i REALLY really don't get it), as all the info must be passed through the calendar theme engine.

my end goal is simple: theme specific cck fields in a given calendar view. The values are already assigned to the view (they end up comprising the teaser), BUT they must each be themed a little differently, which when blocked all together as teaser does not work.

in order to get the week view to display all this info in the first place required some template.php theming. it looks like this:

function mytheme_calendar_node_week($node) {

  $output .= '<div class="calendar weekview">'."\n";
  $output .= theme('calendar_stripe_stripe', $node);

// the switch calculates the time format
  switch ($node->calendar_state) {

<b>...unnecessary for this question and thusly omitted</b>

  }
  
  $output .= '<div class="title">'. l($node->title, "$node->url", array('title' => t('view this item'))) .'</div>'."\n";

<b>  $output .= $node->teaser;</b>

  $output .= '<div class="links">'. theme('links', $node->calendar_links) ."\n</div>";
  $output .= '</div>' . "\n";

  return $output;
}

it's the line $output .= $node->teaser; that contains all the cck field values all wrapped up into one teaser element.
since it is the $output that seems to power all the other displayed elements in the calendar, i assume what i'm looking for would be something like:

$output .= $field_one_field[0]['value']
$output .= $field_two_field[0]['value']
$output .= $field_three_field[0]['value']

naturally however, this is the not the proper syntax.

what is the magic word for:

Print THIS field HERE in a calendar view so that i might THEME it individually

it looks like this: http://dyss.net/artnet/files/cal-ex.gif
and i want to... make every line a different color or something

???

thanks!

best, isaac

Comments

nevets’s picture

My understanding of how it works is that you specify the fields that will show by the fields you select as part of the view. If you need control over how those fields are formatted I would override

function theme_calendar_calendar_node($node, $type) {
  static $set_nodes;

  // Make sure the same node does not get its content altered more than
  // once if it has multiple instances in the calendar.
  if (in_array($node->nid, (array) $set_nodes)) {
    return theme($type, $node);
  }

  // Display the regular teaser view for local events.
  if (!$node->remote && $type == 'calendar_node_day') {
    $node = node_load($node->nid);
    $node->teaser = node_view($node, TRUE, FALSE);
    $node->title = '';
  }
  // For other views, construct a teaser out of the provided fields.
  else {
    if (isset($node->fields) && !isset($node->teaser)) {
      foreach ($node->fields as $field) {
     	 // Locally-created nodes already have output themed, so it was run through check_markup, etc.
       // Remote nodes need some cleanup.
        if ($node->remote) {
          $field = str_replace('\n', "\n", $field);
          // Remove escaping added by ical.
          $field = stripslashes($field);
          // Run through check_markup.
          $field = check_markup($field);
        }
        $node->teaser .= '<div>'. $field .'</div>';
      }
    }
    if (!$node->url && !$node->remote) {
      $node->url = "node/$node->nid";
    }
  }
  // Remote nodes may come in with lengthy descriptions that won't fit
  // in small boxes of year, month, and week calendars.
  if ($type != 'calendar_node_day' && $node->remote) {
    $node->teaser = '';
  }
  $set_nodes[] = $node->nid;
  return theme($type, $node);
}

See the part under the comment 'For other views, construct a teaser out of the provided fields', that is where you could add additional formatting as needed.

d0t15t’s picture

hi nevets,

thanks for your response. the fields i want to show are specified as part of the view (what they don't tell you is that this method does not work for the week view, thus my overriding of the theme mentioned in my post). the guts of this function, i do believe, is what creates the teaser out of each of these individual fields - making one teaser variable out of the many smaller fields. BUT this doesn't allow me to theme each one individually - at least not as i can tell, which leads me to think that outputting individual fields is the way to go.

i guess?

or how could i consider reworking the theme_calendar_calendar_node function to output the teaser in parts or something? or stripes?

best, i

nevets’s picture

I would start with theme_calendar_calendar_node and in particular

$node->teaser .= '<div>'. $field .'</div>';

I would start by make a class name from the field name and adding it to the div.

d0t15t’s picture

excellent - i get it...
i'm still faltering on the syntax tho...

$node->teaser .= '<div class=' . $field . '>'. $field .'</div>'; isn't quite it. i just need to be able to create a different class for each field type... almost!

any other awesome tips?

nevets’s picture

I do not have a 4.7 install to try this on do this may be off a bit, try changing

      foreach ($node->fields as $field) {

to

      foreach ($node->fields as $field_name => $field) {

on the assumption $node->fields is indexed by field name.
Then change your line above to

$node->teaser .= '<div class="' . $field_name . '">'. $field .'</div>';

Note that besides using $field_name for the class I add double quotes around it.

d0t15t’s picture

you have been so kind and helpful on this. i'm pretty sure that totally nailed it!

thanks so much! back to o'reilly's php cookbook for me.

best regards, Isaac

d0t15t’s picture

NEVERMIND - tired eyes... everything works...

i'm overthinking and underthinking at the same time. disregard this next part...

ok - another hitch - looks like the underscores in the class names must be replaced w/ dashes... naturally i can't figure out how/where to implement this guy (if he is right anyway...?)

$field = str_replace('_', "-", $field);

hope that's the last thing...

thx! i

nevets’s picture

For anyone ready along $field = str_replace('_', "-", $field); should be $field_name = str_replace('_', "-", $field_name);