template.php

  1. drupal
    1. 5 themes/garland/template.php
    2. 6 themes/garland/template.php
    3. 7 themes/bartik/template.php
    4. 7 modules/simpletest/tests/themes/test_theme/template.php
    5. 7 themes/garland/template.php
    6. 7 themes/seven/template.php
    7. 8 core/modules/system/tests/themes/test_theme/template.php
    8. 8 core/themes/stark/template.php
    9. 8 core/themes/seven/template.php
    10. 8 core/themes/bartik/template.php

Functions to support theming in the Bartik theme.

Functions & methods

NameDescription
bartik_field__taxonomy_term_referenceImplements theme_field__field_type().
bartik_menu_treeImplements theme_menu_tree().
bartik_preprocess_blockImplements hook_preprocess_HOOK() for block.tpl.php.
bartik_preprocess_htmlImplements hook_preprocess_HOOK() for html.tpl.php.
bartik_preprocess_maintenance_pageImplements hook_preprocess_HOOK() for maintenance-page.tpl.php.
bartik_process_htmlImplements hook_process_HOOK() for html.tpl.php.
bartik_process_maintenance_pageImplements hook_process_HOOK() for maintenance-page.tpl.php.
bartik_process_pageImplements hook_process_HOOK() for page.tpl.php.

File

core/themes/bartik/template.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Functions to support theming in the Bartik theme.
  5. */
  6. /**
  7. * Implements hook_preprocess_HOOK() for html.tpl.php.
  8. *
  9. * Adds body classes if certain regions have content.
  10. */
  11. function bartik_preprocess_html(&$variables) {
  12. if (!empty($variables['page']['featured'])) {
  13. $variables['classes_array'][] = 'featured';
  14. }
  15. if (!empty($variables['page']['triptych_first'])
  16. || !empty($variables['page']['triptych_middle'])
  17. || !empty($variables['page']['triptych_last'])) {
  18. $variables['classes_array'][] = 'triptych';
  19. }
  20. if (!empty($variables['page']['footer_firstcolumn'])
  21. || !empty($variables['page']['footer_secondcolumn'])
  22. || !empty($variables['page']['footer_thirdcolumn'])
  23. || !empty($variables['page']['footer_fourthcolumn'])) {
  24. $variables['classes_array'][] = 'footer-columns';
  25. }
  26. }
  27. /**
  28. * Implements hook_process_HOOK() for html.tpl.php.
  29. */
  30. function bartik_process_html(&$variables) {
  31. // Hook into color.module.
  32. if (module_exists('color')) {
  33. _color_html_alter($variables);
  34. }
  35. }
  36. /**
  37. * Implements hook_process_HOOK() for page.tpl.php.
  38. */
  39. function bartik_process_page(&$variables) {
  40. // Hook into color.module.
  41. if (module_exists('color')) {
  42. _color_page_alter($variables);
  43. }
  44. // Always print the site name and slogan, but if they are toggled off, we'll
  45. // just hide them visually.
  46. $variables['hide_site_name'] = theme_get_setting('toggle_name') ? FALSE : TRUE;
  47. $variables['hide_site_slogan'] = theme_get_setting('toggle_slogan') ? FALSE : TRUE;
  48. if ($variables['hide_site_name']) {
  49. // If toggle_name is FALSE, the site_name will be empty, so we rebuild it.
  50. $variables['site_name'] = filter_xss_admin(variable_get('site_name', 'Drupal'));
  51. }
  52. if ($variables['hide_site_slogan']) {
  53. // If toggle_site_slogan is FALSE, the site_slogan will be empty, so we rebuild it.
  54. $variables['site_slogan'] = filter_xss_admin(variable_get('site_slogan', ''));
  55. }
  56. // Since the title and the shortcut link are both block level elements,
  57. // positioning them next to each other is much simpler with a wrapper div.
  58. if (!empty($variables['title_suffix']['add_or_remove_shortcut']) && $variables['title']) {
  59. // Add a wrapper div using the title_prefix and title_suffix render elements.
  60. $variables['title_prefix']['shortcut_wrapper'] = array(
  61. '#markup' => '<div class="shortcut-wrapper clearfix">',
  62. '#weight' => 100,
  63. );
  64. $variables['title_suffix']['shortcut_wrapper'] = array(
  65. '#markup' => '</div>',
  66. '#weight' => -99,
  67. );
  68. // Make sure the shortcut link is the first item in title_suffix.
  69. $variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100;
  70. }
  71. }
  72. /**
  73. * Implements hook_preprocess_HOOK() for maintenance-page.tpl.php.
  74. */
  75. function bartik_preprocess_maintenance_page(&$variables) {
  76. // By default, site_name is set to Drupal if no db connection is available
  77. // or during site installation. Setting site_name to an empty string makes
  78. // the site and update pages look cleaner.
  79. // @see template_preprocess_maintenance_page
  80. if (!$variables['db_is_active']) {
  81. $variables['site_name'] = '';
  82. }
  83. drupal_add_css(drupal_get_path('theme', 'bartik') . '/css/maintenance-page.css');
  84. }
  85. /**
  86. * Implements hook_process_HOOK() for maintenance-page.tpl.php.
  87. */
  88. function bartik_process_maintenance_page(&$variables) {
  89. // Always print the site name and slogan, but if they are toggled off, we'll
  90. // just hide them visually.
  91. $variables['hide_site_name'] = theme_get_setting('toggle_name') ? FALSE : TRUE;
  92. $variables['hide_site_slogan'] = theme_get_setting('toggle_slogan') ? FALSE : TRUE;
  93. if ($variables['hide_site_name']) {
  94. // If toggle_name is FALSE, the site_name will be empty, so we rebuild it.
  95. $variables['site_name'] = filter_xss_admin(variable_get('site_name', 'Drupal'));
  96. }
  97. if ($variables['hide_site_slogan']) {
  98. // If toggle_site_slogan is FALSE, the site_slogan will be empty, so we rebuild it.
  99. $variables['site_slogan'] = filter_xss_admin(variable_get('site_slogan', ''));
  100. }
  101. }
  102. /**
  103. * Implements hook_preprocess_HOOK() for block.tpl.php.
  104. */
  105. function bartik_preprocess_block(&$variables) {
  106. // In the header region visually hide block titles.
  107. if ($variables['block']->region == 'header') {
  108. $variables['title_attributes_array']['class'][] = 'element-invisible';
  109. }
  110. }
  111. /**
  112. * Implements theme_menu_tree().
  113. */
  114. function bartik_menu_tree($variables) {
  115. return '<ul class="menu clearfix">' . $variables['tree'] . '</ul>';
  116. }
  117. /**
  118. * Implements theme_field__field_type().
  119. */
  120. function bartik_field__taxonomy_term_reference($variables) {
  121. $output = '';
  122. // Render the label, if it's not hidden.
  123. if (!$variables['label_hidden']) {
  124. $output .= '<h3 class="field-label">' . $variables['label'] . ': </h3>';
  125. }
  126. // Render the items.
  127. $output .= ($variables['element']['#label_display'] == 'inline') ? '<ul class="links inline">' : '<ul class="links">';
  128. foreach ($variables['items'] as $delta => $item) {
  129. $output .= '<li class="taxonomy-term-reference-' . $delta . '"' . $variables['item_attributes'][$delta] . '>' . drupal_render($item) . '</li>';
  130. }
  131. $output .= '</ul>';
  132. // Render the top-level DIV.
  133. $output = '<div class="' . $variables['classes'] . (!in_array('clearfix', $variables['classes_array']) ? ' clearfix' : '') . '">' . $output . '</div>';
  134. return $output;
  135. }
Login or register to post comments