[support] Page with two Sections

Dale McGladdery torelad at gmail.com
Sat Sep 22 00:34:00 UTC 2007


> The node itself is indeed CCK. I know Views, but as I said, I don't see
> a way to generate two lists of the node return set, one list of links
> and one list of content, on the same page. If there IS such a way, let
> me know. :)

Views is amazing once you wrap your head around! With the caveat that
I've done this before, but haven't tested this specific code .....

If you create a list view, the Views Theme Wizard gives code along the
following lines to place in your template.php file:

function phptemplate_views_view_list_faq($view, $nodes, $type) {
  <<< SNIP >>>
  foreach ($nodes as $i => $node) {
    $vars = $base_vars;
    $vars['node'] = $node;
    $vars['count'] = $i;
    $vars['stripe'] = $i % 2 ? 'even' : 'odd';
    foreach ($view->field as $id => $field) {
      $name = $field_names[$id];
      $vars[$name] = views_theme_field('views_handle_field',
$field['queryname'], $fields, $field, $node, $view);
      if (isset($field['label'])) {
        $vars[$name . '_label'] = $field['label'];
      }
    }
    $items[] = _phptemplate_callback('views-list-faq', $vars);
  }
  if ($items) {
    return theme('item_list', $items);
  }
}

This line calls out to the template file views-list-faq.tpl.php for formatting:
    $items[] = _phptemplate_callback('views-list-faq', $vars);

With the following change, you can format two different things with
the same data:
    $link_items[] = _phptemplate_callback('views-list-faq-linkitem', $vars);
    $content_items[] =
_phptemplate_callback('views-list-faq-contentitem', $vars);

This will call views-list-faq-linkitem.tpl.php and
views-list-faq-contentitem.tpl.php. The names of the variables are the
same for each file, so the info provided by the Theme Wizard for the
tpl.php file is valid for both of these files.

This code:
  if ($items) {
    return theme('item_list', $items);
  }

calls theme_item_list
(http://api.drupal.org/api/function/theme_item_list/5) on the array
named $items. Each entry in $items is just a text string (created
using the tpl.php file via _phptemplate_callback). Instead of calling
theme_item_list to convert the array of strings into an unordered
list, you can do something like this:

  if ($link_items) {
    $result = '<div class="faq-links">';
    $result .= theme('item_list', $link_items);
    $result .= '</div>';
    $result .= '<div class="faq-contents">';
    foreach($content_items as $item) {
      $result .= $item;
    }
    $result .= '</div>';
    return $result;
  }

C'est voila!


More information about the support mailing list