Note that there are some explanatory texts on larger screens.

plurals
  1. POCan you call one Drupal views template for multiple views?
    primarykey
    data
    text
    <p>I've used the Views Theming Wizard to output a template and it gave me the following chunk of code to go in template.php.</p> <p>I'd prefer to just maintain the one template, so all my functions will be calling the same one, and rather than writing numerous versions of the same function, I'm wondering if there's a way to string function names together? Something like:</p> <pre><code>function phptemplate_views_view_list_recent_articles($view, $nodes, $type), phptemplate_views_view_list_popular_articles($view, $nodes, $type) { $fields = _views_get_fields(); $taken = array(); // Set up the fields in nicely named chunks. foreach ($view-&gt;field as $id =&gt; $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' =&gt; $view, 'view_type' =&gt; $type, ); foreach ($nodes as $i =&gt; $node) { $vars = $base_vars; $vars['node'] = $node; $vars['count'] = $i; $vars['stripe'] = $i % 2 ? 'even' : 'odd'; foreach ($view-&gt;field as $id =&gt; $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-first-with-abstract', $vars); } if ($items) { return theme('item_list', $items); } } </code></pre> <p>Thanks,<br /> Steve</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload