Newer
Older
<?php
/**
Ted Serbinski
committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
* About this file
*
* The template.php file is one of the most useful files when creating templates. It allows you to place
* all of your custom theme logic, plus specific Drupal related theme functions into one place. You should
* place any code in here that directly affects your theme -- changing menu structures, styling content,
* theming pages differently based on content, and so forth.
*
*/
/**
* Overriding theme functions
*
* Overriding theme functions in Drupal is the best way to alter the way Drupal themes various sections of
* a website. Scattered throughout Drupal core and also used in downloaded, contribute modules, is the use
* theme_some_function().
*
* This is a special type of function in Drupal as it can be overridden by the theme, by placing a copy of
* that function in this file. Copy the entire contents of the function, then simply rename it using the name
* of the theme the template.php lives in.
*
* original: theme_breadcrumb()
* theme override: zen_breadcrumb()
*
* See the following example. In this theme, we want to change all of the breacrumb separator links from
* a >> to an arrow -->
*/
/**
* Return a themed breadcrumb trail.
*
* @param $breadcrumb
* An array containing the breadcrumb links.
* @return a string containing the breadcrumb output.
*/
function zen_breadcrumb($breadcrumb) {
if (!empty($breadcrumb)) {
return '<div class="breadcrumb">'. implode(' → ', $breadcrumb) .'</div>';
}
}
/**
* Creating new regions
*
* If you wish to create new regions for your theme to place block content into, you want to override this
* theme function. By declaring the variable name and giving it a human readable name, you create new regions
* for your theme that are then available on the administer > site building > blocks page. On this page you can
* then select which regions various blocks should be placed.
*/
/**
* Declare the available regions implemented by this engine.
*
* @return
* An array of regions. The first array element will be used as the default region for themes.
*/
function zen_regions() {
return array(
'left' => t('left sidebar'),
'right' => t('right sidebar'),
'content_top' => t('content top'),
'content_bottom' => t('content bottom'),
'header' => t('header'),
'footer' => t('footer')
);
Ted Serbinski
committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
}
/**
* Creating new variables for your theme
*
* The most powerful function available to themers is the _phptemplate_variables() function. It allows you
* to pass newly created variables to different template files in your theme. Or even unset ones you don't want
* to use.
*
* It works by switching on the hook, which can be:
* - page
* - node
* - comment
* - block
*
* By switching on this hook you can send different variables to your main page.tpl.php file, your node.tpl.php
* (and any other derivative node template file, like node-page.tpl.php), comment.tpl.php, and block.tpl.php
*
*/
/**
* Intercept template variables
*
* @param $hook
* The name of the theme function being executed
* @param $vars
* A sequential array of variables passed to the theme function.
*/
/**
* Note this is just an example so it is commented out
*
function _phptemplate_variables($hook, $vars = array()) {
// variable available to all template files
$vars['img_path'] = my_custom_function_get_image_path_to_my_image_server();
switch ($hook) {
case 'page':
// if we're on the homepage we want to load a different template file
if ($vars['is_front']) {
$vars['template_file'] = 'page-index.tpl.php';
}
break;
case 'node':
// get the currently logged in user
global $user;
// set a new $is_admin variable
// this is determined by looking at the currently logged in user and seeing if they are in the role 'admin'
$vars['is_admin'] = in_array('admin', $user->roles);
break;
}
return $vars;
}
*
*/