Php 您可以为多个视图调用一个Drupal视图模板吗?
我已经使用视图主题化向导输出了一个模板,它给了我以下代码块进入template.php 我更喜欢只维护一个模板,这样我的所有函数都将调用同一个模板,而不是编写同一个函数的多个版本,我想知道是否有办法将函数名串在一起?比如:Php 您可以为多个视图调用一个Drupal视图模板吗?,php,drupal,drupal-views,drupal-5,Php,Drupal,Drupal Views,Drupal 5,我已经使用视图主题化向导输出了一个模板,它给了我以下代码块进入template.php 我更喜欢只维护一个模板,这样我的所有函数都将调用同一个模板,而不是编写同一个函数的多个版本,我想知道是否有办法将函数名串在一起?比如: function phptemplate_views_view_list_recent_articles($view, $nodes, $type), phptemplate_views_view_list_popular_articles($view, $nodes, $t
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);
}
}
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);
}
谢谢,Steve您只需要调用实际函数的一个版本即可 比如:
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);
}
}
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);
}
上面的一个修正让我慢了半个小时。。。您需要包括一份申报表:
return actual_template_function($view, $nodes, $type);
除此之外,它工作得很好。为什么您的纯Drupal/PHP问题标记为JavaScript?