| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* ABOUT
|
| 5 |
*
|
| 6 |
* The template.php file is one of the most useful files when creating or modifying Drupal themes.
|
| 7 |
* You can add new regions for block content, modify or override Drupal's theme functions,
|
| 8 |
* intercept or make additional variables available to your theme, and create custom PHP logic.
|
| 9 |
* For more information, please visit the Theme Developer's Guide on Drupal.org:
|
| 10 |
* http://drupal.org/node/509
|
| 11 |
*/
|
| 12 |
|
| 13 |
|
| 14 |
/**
|
| 15 |
* MODIFYING OR CREATING REGIONS
|
| 16 |
*
|
| 17 |
* Regions are areas in your theme where you can place blocks.
|
| 18 |
* The default regions used in themes are "left sidebar", "right sidebar", "header", and "footer", although you can create
|
| 19 |
* as many regions as you want. Once declared, they are made available to the page.tpl.php file as a variable.
|
| 20 |
* For instance, we use <?php print $header ?> for the placement of the "header" region in page.tpl.php.
|
| 21 |
*
|
| 22 |
* By going to the administer > site building > blocks page you can choose which regions various blocks should be placed.
|
| 23 |
* New regions you define here will automatically show up in the drop-down list by their human readable name.
|
| 24 |
*/
|
| 25 |
|
| 26 |
|
| 27 |
/**
|
| 28 |
* Declare the available regions implemented by this engine.
|
| 29 |
*
|
| 30 |
* @return
|
| 31 |
* An array of regions. The first array element will be used as the default region for themes.
|
| 32 |
* Each array element takes the format: variable_name => t('human readable name')
|
| 33 |
*/
|
| 34 |
function danger4k_regions() {
|
| 35 |
return array(
|
| 36 |
'left' => t('left sidebar'),
|
| 37 |
'right' => t('right sidebar'),
|
| 38 |
'content_top' => t('content top'),
|
| 39 |
'content_bottom' => t('content bottom'),
|
| 40 |
'header' => t('header'),
|
| 41 |
'footer' => t('footer')
|
| 42 |
);
|
| 43 |
}
|
| 44 |
|
| 45 |
/**
|
| 46 |
* OVERRIDING THEME FUNCTIONS
|
| 47 |
*
|
| 48 |
* The Drupal theme system uses special theme functions to generate HTML output automatically.
|
| 49 |
* Often we wish to customize this HTML output. To do this, we have to override the theme function.
|
| 50 |
* You have to first find the theme function that generates the output, and then "catch" it and modify it here.
|
| 51 |
* The easiest way to do it is to copy the original function in its entirety and paste it here, changing
|
| 52 |
* the prefix from theme_ to zen_. For example:
|
| 53 |
*
|
| 54 |
* original: theme_breadcrumb()
|
| 55 |
* theme override: danger4k_breadcrumb()
|
| 56 |
*
|
| 57 |
* See the following example. In this theme, we want to change all of the breadcrumb separator links from >> to ::
|
| 58 |
*
|
| 59 |
*/
|
| 60 |
|
| 61 |
/**
|
| 62 |
* Return a themed breadcrumb trail.
|
| 63 |
*
|
| 64 |
* @param $breadcrumb
|
| 65 |
* An array containing the breadcrumb links.
|
| 66 |
* @return a string containing the breadcrumb output.
|
| 67 |
*/
|
| 68 |
/* function danger4k_breadcrumb($breadcrumb) {
|
| 69 |
if (!empty($breadcrumb)) {
|
| 70 |
return '<div class="breadcrumb">'. implode(' :: ', $breadcrumb) .'</div>';
|
| 71 |
}
|
| 72 |
} */
|
| 73 |
|
| 74 |
|
| 75 |
/**
|
| 76 |
* CREATE OR MODIFY VARIABLES FOR YOUR THEME
|
| 77 |
*
|
| 78 |
* The most powerful function available to themers is the _phptemplate_variables() function. It allows you
|
| 79 |
* to pass newly created variables to different template (tpl.php) files in your theme. Or even unset ones you don't want
|
| 80 |
* to use.
|
| 81 |
*
|
| 82 |
* It works by switching on the hook, or name of the theme function, such as:
|
| 83 |
* - page
|
| 84 |
* - node
|
| 85 |
* - comment
|
| 86 |
* - block
|
| 87 |
*
|
| 88 |
* By switching on this hook you can send different variables to page.tpl.php file, node.tpl.php
|
| 89 |
* (and any other derivative node template file, like node-forum.tpl.php), comment.tpl.php, and block.tpl.php
|
| 90 |
*
|
| 91 |
*/
|
| 92 |
|
| 93 |
|
| 94 |
/**
|
| 95 |
* Intercept template variables
|
| 96 |
*
|
| 97 |
* @param $hook
|
| 98 |
* The name of the theme function being executed
|
| 99 |
* @param $vars
|
| 100 |
* A sequential array of variables passed to the theme function.
|
| 101 |
*/
|
| 102 |
|
| 103 |
function _phptemplate_variables($hook, $vars = array()) {
|
| 104 |
switch ($hook) {
|
| 105 |
// Send a new variable, $has_terms, to see wether the current node has any terms
|
| 106 |
case 'node':
|
| 107 |
if(count(taxonomy_node_get_terms($vars['node']->nid)))
|
| 108 |
$vars['has_terms'] = TRUE;
|
| 109 |
else
|
| 110 |
$vars['has_terms'] = FALSE;
|
| 111 |
}
|
| 112 |
|
| 113 |
return $vars;
|
| 114 |
}
|