A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearCan you call one Drupal views template for multiple views? - page 1
User InfoPosts
Can you call one Drupal views template for multiple views?#1
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.

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:

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


Thanks,
Steve

posted date: 2008-12-08 17:43:00


Re: Can you call one Drupal views template for multiple views?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-08 17:43:01


Re: Can you call one Drupal views template for multiple views?#3
Why is your purely Drupal/PHP question marked JavaScript?

posted date: 2008-12-08 19:54:00


Re: Can you call one Drupal views template for multiple views?#4
Thanks Eugene. Corrected.

posted date: 2008-12-09 07:30:00


Re: Can you call one Drupal views template for multiple views?#5
You could just have the templates you need call one version of the actual function.Something like:function phptemplate_views_view_list_recent_articles($view, $nodes, $type){ actual_template_function($view, $nodes, $type);}function phptemplate_views_view_list_popular_articles($view, $nodes, $type){ actual_template_function($view, $nodes, $type);}

posted date: 2008-12-09 08:05:00


Re: Can you call one Drupal views template for multiple views?#6
One correction above that slowed me down for a 1/2 hour... your need to include a return:return actual_template_function($view, $nodes, $type);Other than that, works great.

posted date: 2009-01-30 11:39:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.