summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFarsheed2006-10-17 04:54:45 (GMT)
committer Farsheed2006-10-17 04:54:45 (GMT)
commit7081db4346b4d60df229dbaf923e51d9605c7cf1 (patch)
tree0e6985b26aff3bfd572db40ce76372066464684d
parentcbe14d6d4dc712fc3addcdcd87cde3df4f8cd4f4 (diff)
Modified the help text to be more succinct and easier to understand. Modified the breadcrumb to be a double colon because the long arrow looks awkward. Changed the _phptemplate_variables to be a semi-useful example instead of a giant block that is commented out. I am still uncomfortable with this file as it went from a very tiny file to an extremely verbose one. I'm recommending trimming it even more, if not just providing a link to an example template.php file posted on drupal.org with more thorough documentation.
-rw-r--r--template.php165
1 files changed, 72 insertions, 93 deletions
diff --git a/template.php b/template.php
index 3083dc7..bc502bf 100644
--- a/template.php
+++ b/template.php
@@ -1,62 +1,35 @@
<?php
/**
- * About this file
+ * ABOUT
*
- * 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 -->
+ * The template.php file is one of the most useful files when creating or modifying Drupal themes.
+ * You can add new regions for block content, modify or override Drupal's theme functions,
+ * intercept or make additional variables available to your theme, and create custom PHP logic.
+ * For more information, please visit the Theme Developer's Guide on Drupal.org:
+ * http://drupal.org/node/509
*/
- /**
- * 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(' &#8594; ', $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.
+* MODIFYING OR CREATING REGIONS
+*
+* Regions are areas in your theme where you can place blocks.
+* The default regions used in themes are "left sidebar", "right sidebar", "header", and "footer", although you can create
+* as many regions as you want. Once declared, they are made available to the page.tpl.php file as a variable.
+* For instance, we use <?php print $header ?> for the placement of the "header" region in page.tpl.php.
+*
+* By going to the administer > site building > blocks page you can choose which regions various blocks should be placed.
+* New regions you define here will automatically show up in the drop-down list by their human readable name.
*/
+
/**
* 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.
+ * An array of regions. The first array element will be used as the default region for themes.
+ * Each array element takes the format: variable_name => t('human readable name')
*/
function zen_regions() {
return array(
@@ -67,27 +40,57 @@ function zen_regions() {
'header' => t('header'),
'footer' => t('footer')
);
-}
+}
+/**
+ * OVERRIDING THEME FUNCTIONS
+ *
+ * The Drupal theme system uses special theme functions to generate HTML output automatically.
+ * Often we wish to customize this HTML output. To do this, we have to override the theme function.
+ * You have to first find the theme function that generates the output, and then "catch" it and modify it here.
+ * The easiest way to do it is to copy the original function in its entirety and paste it here, changing
+ * the prefix from theme_ to zen_. For example:
+ *
+ * original: theme_breadcrumb()
+ * theme override: zen_breadcrumb()
+ *
+ * See the following example. In this theme, we want to change all of the breadcrumb separator links from >> to ::
+ *
+ */
+/**
+ * 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 variables for your theme
+ * CREATE OR MODIFY 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.
+ * The most powerful function available to themers is the _phptemplate_variables() function. It allows you
+ * to pass newly created variables to different template (tpl.php) 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
+ * It works by switching on the hook, or name of the theme function, such as:
+ * - 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
+ * By switching on this hook you can send different variables to page.tpl.php file, node.tpl.php
+ * (and any other derivative node template file, like node-forum.tpl.php), comment.tpl.php, and block.tpl.php
*
*/
+
/**
* Intercept template variables
*
@@ -97,46 +100,22 @@ function zen_regions() {
* 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 show a special graphic
- if ($vars['is_front']) {
- $vars['home_banner'] = 'some_image.jpg';
+ // Send a new variable, $logged_in, to page.tpl.php to tell us if the current user is logged in or out.
+ case 'page':
+ global $user;
+ // An anonymous user has a user id of zero.
+ if($user->uid > 0) {
+ // the user is logged in
+ $vars['logged_in'] = TRUE;
}
-
- 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;
-
- case 'comment':
- // we load the node object that the current comment is attached to
- $node_author = node_load($vars['comment']->nid);
- // if the author of this comment is equal to the author of the node, we set a variable
- // then in our theme we can theme this comment differently to stand out
- $vars['author_comment'] = $vars['comment']->uid == $node_author->uid ? TRUE : FALSE;
- break;
+ else {
+ // the user has logged out
+ $vars['logged_in'] = FALSE;
+ }
+ break;
}
return $vars;
}
-
- *
- */
- \ No newline at end of file