How to change HTML code of drupal 5 viewer module

I am using Drupal 5 and have a lot of views that I want to change the output. Using the view wizard I can create a different template for each instance, but I want to make the same changes in all of my views and have 30 files in the seams of the directory so how heck of a lot of maintenance and code. Does anyone know if there is a default way to access all views at the same time and then using what I currently have for one output?

Here's what I have now:

views list-house _______ _______ articles latest.tpl.php

<?php 
/**
 * views template to output one 'row' of a view.
 * This code was generated by the views theming wizard
 * Date: November 17, 2008 - 2:07pm
 * View: home_articles_latest
 *
 * Variables available:
 * $view -- the entire view object. Important parts of this object are
 *   home_articles_latest, .
 * $view_type -- The type of the view. Probably 'page' or 'block' but could
 *   also be 'embed' or other string passed in from a custom view creator.
 * $node -- the raw data. This is not a real node object, but will contain
 *   the nid as well as other support fields that might be necessary.
 * $count -- the current row in the view (not TOTAL but for this page) starting
 *   from 0.
 * $stripe -- 'odd' or 'even', alternating. * $title -- Display the title of the node.
 * $title_label -- The assigned label for $title
 * $comment_count -- This will display the comment count.
 * $comment_count_label -- The assigned label for $comment_count
 * $field_abstract_value -- 
 * $field_abstract_value_label -- The assigned label for $field_abstract_value
 *
 * This function goes in your views-list-home_articles_latest.tpl.php file
 */


 //now we add the stylesheet...
 //drupal_add_css(path_to_theme() .'/views-list-home_articles_latest.css');

  ?>
  <?php print $view ?>
<div class="view-label view-field-title">
  <?php print $title_label ?>
</div>
<div class="view-field view-data-title">
  <?php print $title?>
</div>

<?php if ($comment_count != '0' && $view_type == 'block'): ?>
<div class="view-label view-field-comment-count">
  <?php print $comment_count_label ?>
</div>
<div class="view-field view-data-comment-count">
  <?php print $add?><?php print $comment_count?>
</div>
<?php endif; ?>

<?php if ($count == 0): ?>
<div class="view-label view-field-field-abstract-value">
  <?php print $field_abstract_value_label ?>
</div>
<div class="view-field view-data-field-abstract-value">
  <?php print $field_abstract_value?>
</div>
<?php endif; ?>

      

in template.php

/**
 * views template to output a view.
 * This code was generated by the views theming wizard
 * Date: November 17, 2008 - 2:07pm
 * View: home_articles_latest
 *
 * This function goes in your template.php file
 */
function phptemplate_views_view_list_home_articles_latest($view, $nodes, $type) {
  $fields = _views_get_fields();

  $taken = array();

  // Set up the fields in nicely named chunks.
  foreach ($view->field as $id => $field) {
    $field_name = $field['field'];
    if (isset($taken[$field_name])) {
      $field_name = $field['queryname'];
    }
    $taken[$field_name] = true;
    $field_names[$id] = $field_name;
  }

  // Set up some variables that won't change.
  $base_vars = array(
    'view' => $view,
    'view_type' => $type,
  );

  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-home_articles_latest', $vars);
  }
  if ($items) {
    return theme('item_list', $items);
  }
}

      

Thanks
Steve

+1


source to share


3 answers


I think that simply creating a file named "views-list.tpl.php" will apply to all list-style views (unless a more specific .tpl.php file is specified).



Otherwise, there might be a way to get what you want using the theme's features.

+2


source


I believe that each template should be updated independently if you are talking about something that happens inside the view template. I don't know how to update only one small part of n views.



If you have a header that you place above the template for each view, you can do so with a helper function in template.php or a conditional function in node.tpl.php. But if he gets inside, I think you are out of luck.

0


source


There is no way for modules to expose tpl files by default in 5 views, so the template name won't help you. The key is a function that is placed in your template.php file, "phptemplate_views_view_list_home_articles_latest". This is a PHP function that intercepts the rendering of any kind of list named "home_articles_latest". If you want it to capture ALL views, you simply change the name of the function itself to: "phptemplate_views_view"

Keep in mind that this will affect everything - assembling sidebar blocks using views, RSS feeds, etc.

0


source







All Articles