Drupal 7在我的内容类型中为每个分组部分添加标题?

时间:2014-02-25 17:31:34

标签: drupal-7 drupal-fields drupal-content-types

我创建了一个内容类型,它有大约5个组,这些组都是垂直标签。

由于某种原因,“字段”组标签不适用于垂直选项卡。 <h2>标记始终为:<h2 class="element-invisible">Vertical Tabs</h2>。标题始终为Vertical Tabs,无论manage fields中设置了什么,它始终具有类element-invisible

我注意到在使用垂直标签的某些主题中完全相同。

我还注意到这些主题在每个垂直选项卡上方都有一个额外的标题标记,其中显示了该组的标题。 (adaptivetheme)就是一个很好的例子。

无论如何,对于实际问题......

如何在我的内容类型中为每个分组部分(垂直标签)添加标题?

  

注意:这是用于添加内容而不是显示的实际表单   创建的内容。

对此的任何帮助都非常适用。

3 个答案:

答案 0 :(得分:1)

使用Drupal 7 content theming为您的内容类型添加标题。例如,如果您的内容类型名为 mycontent ,则在主题文件夹中创建以下脚本:

{theme path}/page--node--mycontent.tpl.php

要预处理内容类型,请使用以下函数:

function mycontent_preprocess_page(&$vars) {
    if (isset($vars['node']->type)) { 
        $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
    }
}

有关template_preprocess_page函数的更多信息,请访问here

答案 1 :(得分:1)

您可以在主题的template.php或自定义模块中自定义内容类型表单。记录在案here。例如,如果您的主题MYMODULE中有自定义模块使用自定义内容类型文章,那么您可以自定义如下:

<?php
/**
* Implements hook_theme().
*/
function MYMODULE_theme($existing, $type, $theme, $path) {
  return array(
    'article_node_form' => array(
      'render element' => 'form',
      'template' => 'article-node-form',
      // this will set to module/theme path by default:
      'path' => drupal_get_path('module', 'MYMODULE'),
    ),
  );
}
?>

输出自定义数据:

<?php
/**
* Preprocessor for theme('article_node_form').
*/
function template_preprocess_article_node_form(&$variables) {
  // nodeformcols is an alternative for this solution.
  if (!module_exists('nodeformcols')) {
    $variables['sidebar'] = array();   // Put taxonomy fields in sidebar.
    $variables['sidebar'][] = $variables['form']['field_tags'];
    hide($variables['form']['field_tags']);
    // Extract the form buttons, and put them in independent variable.
    $variables['buttons'] = $variables['form']['actions'];
    hide($variables['form']['actions']);
  }
}
?>

答案 2 :(得分:1)

这个问题的其他答案都在正确的轨道上。负责垂直选项卡标题的代码是theme_vertical_tabs文件中的includes/form.inc函数。

如果您有自己的主题,可以在主题的template.php文件中复制和更改此功能以覆盖它:

function YOUR_THEME_NAME_vertical_tabs($variables) {
  $element = $variables['element'];

  // Add required JavaScript and Stylesheet.
  drupal_add_library('system', 'drupal.vertical-tabs');

  // Following line changed to use title set in field settings and remove class="element-invisible
  $output = '<h2>' . t($element['#title']) . '</h2>';  
  $output .= '<div class="vertical-tabs-panes">' . $element['#children'] . '</div>';

  return $output;
}

如果您希望在内容编辑屏幕中显示垂直标签标题,并且您有管理主题设置,则需要对管理主题进行上述修改。

相关问题