Archive for May, 2007

172 CHAPTER 5 ADDING (Photoshop web design) AND CUSTOMIZING THEMES

Thursday, May 3rd, 2007

172 CHAPTER 5 ADDING AND CUSTOMIZING THEMES Overriding Themable Functions The preceding section demonstrated how to work with the default tpl.phpfiles to modify your theme. Each of these files represents an override to a themable function from the Drupal core. While theme_page, theme_node, theme_comment, theme_box, and theme_block may be the most important themable functions, and thus have the greatest and most direct impact on the appearance of your site, they are by no means the only functions that are available for modification. Core Drupal includes dozens more themable functions, and most contributed modules add to the list as well. Learning how to find and override any themable function you wish is essential to having full mastery over your Drupal site. How to Find Themable Functions Finding themable functions, at the most basic level, is easy. You just open the code and search for function theme_. Everything that turns up is a themable function and can be overridden. This isn t much consolation, however, when you are looking at your site and you want to change a particular HTML snippet in a particular way. How do you know which themable function is responsible for a given widget or element in your Drupal site? Unfortunately, Drupal doesn t provide an easy built-in method for doing this. However, there is an easy way to fix this, and doing so gives you a good opportunity to peer further into the world of Drupal theming. Exercise 5-3 gives you a tool for identifying themable functions. Exercise 5-3. Identify Themable Functions The goal of this exercise is to modify the function responsible for calling themable functions in such a way that allows you to see in the HTML output which function was called. To do this, you will wrap the output from each call to a themable function in HTML comments like this: result of the themable function This way, you can look at the source code of a generated page and know exactly which themable function to override in order to change the output. This will be a handy tool while designing the theme for your site, but you won t want to use it on a production site. To begin, locate the includes/theme.inc file and make a backup copy, which you will use later to restore your Drupal installation to its original state when you re finished with this exercise. In theme.inc, find the theme() function around line 160. This is the function that is responsible for determining exactly which themable function to call. It looks first for a function specific to your theme, then to the theme engine, and finally to the default theme_foo function, calling the first one found. Replace the theme() function with the following code: function theme() { global $theme, $theme_engine; if ($theme === NULL) { // Initialize the enabled theme. $theme = init_theme(); }
Note: In case you are looking for affordable webhost to host and run your web application check Vision http web server services

Web hosting bandwidth - CHAPTER 5 ADDING AND CUSTOMIZING THEMES 171

Thursday, May 3rd, 2007

CHAPTER 5 ADDING AND CUSTOMIZING THEMES 171 Exercise 5-2. Use Random Colors for Blocks If you wanted to have each block on the page have a randomly chosen color, this would be a great opportunity to add the logic for choosing the color. Naturally, you could do this directly in the block.tpl.php file, but that would make the file harder to read for your graphic designer, who doesn t care how you determine the color, only that it is available in a nice, clean variable to be applied inside the template. First, add the following _phptemplate_variables function to the template.php file in your theme. If the template.php file doesn t exist, create it (make sure to begin the file with

subject; ?>
content; ?>

Now when you access your site, every block should have a border with a randomly chosen color. Manipulations at this point in the code are useful mainly for adding decoration or elements that are external to your site s logic. Most of the page execution code has been run by the time _phptemplate_variables gets called, which means it is quite limited in its possibilities. Furthermore, keep in mind that this is the theme for your site, which, by definition, should concern itself exclusively with visual elements and layout. Nevertheless, for tasks like using random colors for blocks, it is a useful place to make customizations.
Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services

Web server iis - 170 CHAPTER 5 ADDING AND CUSTOMIZING THEMES

Thursday, May 3rd, 2007

170 CHAPTER 5 ADDING AND CUSTOMIZING THEMES

Most notable is the $contentvariable, which contains the main feature of the page a node, a user, a list of taxonomy terms, or any other content. The template ends by printing the $closurevariable directly before the closing tag: This is necessary to guarantee that modules have a chance to insert scripts at the bottom of the page. This is usually done in cases where the loading order of a script needs to be controlled; scripts at the bottom of the page will load after scripts earlier on the page, such as those needed for transforming text areas into WYSIWYG editors. Passing Extra Variables to Templates The variables listed for each of the previous tpl.php template files are all you need to support the normal functioning of your Drupal site. In case you would like to push other information into the template files, there is a mechanism for adding variables. The following function must be added to a file named template.php in your theme s directory: function _phptemplate_variables($hook, $vars) { … return $vars; } For Bluemarine, this would be in the file themes/bluemarine/template.php. The $hook variable is the name of the themable function being called and subsequently the root of the name of the template file to which the variables are headed. The $vars variable is an associative array containing the default variables as described in the preceding section. Thus, when the theme(’block’) function is called, _phptemplate_variables will also be called with the parameters ‘block’ and an array of the variables associated with the block.tpl.phptemplate: $block, $id, $block_id, $zebra, $block_zebra, and $is_front. At this point, you have the chance to add values to the array, or even change those that are already inside it. The $vars array that you return will determine which variables are visible to the block.tpl.php file. The same is true for each of the default tpl.php files, as well as any other template files that you may have added, such as node-type-specific files or overrides of themable functions. Exercise 5-2 demonstrates how to pass extra variables to a template.
Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services

Web hosting bandwidth - 168 CHAPTER 5 ADDING AND CUSTOMIZING THEMES

Wednesday, May 2nd, 2007

168 CHAPTER 5 ADDING AND CUSTOMIZING THEMES Table 5-8. Continued Variable Description $head_title The page s title, for display in the tag. The $head_title variable is constructed either from $title and $site_name or $site_name and $site_slogan. $help Help text for the page, if it is available. $language The two-letter language code based on the locale in which the site is being displayed; for example, en for English or de for German. $layout A string (’left’, ‘right’, ‘both’, or empty) that indicates if and where blocks are found for this page. The idea is that the template can check which layout is being demanded and react accordingly. $logo The path to the image to be used as the site logo. $messages Status and error messages to the user. $mission The text of the mission statement as defined by the Mission field on the admin/settings page. $onload_attributes HTML code added inside the opening <body> tag of the page. Its main purpose is to expose the onload parameter of the <body> tag to modules so that they can trigger events when the page is loaded in the browser. This is the mechanism that allows the WYSIWYG editors like TinyMCE to function properly; the JavaScript that loads the editors will be embedded in $onload_attributes. $primary_links An array of links that are defined in the Primary Link Settings field of the admin/themes/settings page. $search_box The HTML to render the search box, if it is enabled. $secondary_links An array of links that are defined in the Secondary Link Settings field of the admin/themes/settings page. $sidebar_left HTML to render the left sidebar. $sidebar_right HTML to render the right sidebar. $site_name The name of the site, as specified by you from the admin/settings page. $site_slogan The text for the site slogan that is defined on the admin/settings page. $styles HTML for the <head> tag of the page that consists of style sheet imports in the correct order. $tabs HTML to render tabbed navigation for a page. An example of this is the view and edit tabs that are visible on node pages (when you re logged in and have the right privileges). $title The title of this page. The PHPTemplate theme engine does not provide a page.tpl.php implementation; this is the realm of the individual themes. The page.tpl.php file provided by the Bluemarine theme is a good example of what needs to happen and what issues need to be addressed. As the file is relatively long, I ll discuss only excerpts here. The first two lines are the DOCTYPE declaration and the opening <html> tag. Noteworthy is that the document is declared to be XHTML 1.0 STRICT and that the lang and xml:lang parameters of the <html> tag are both set dynamically using the $language variable provided to the template. <br />Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision <a href="http://j2ee.a1websitehosting.net">php5 hosting</a> services </p> </div> <p class="postmetadata">Posted in <a href="http://mysql5.premiumwebsitehosting.net/category/mysql5/" title="View all posts in MySQL5" rel="category tag">MySQL5</a> | <a href="http://mysql5.premiumwebsitehosting.net/mysql5/web-hosting-bandwidth-168-chapter-5-adding-and-customizing-themes/#respond" title="Comment on Web hosting bandwidth - 168 CHAPTER 5 ADDING AND CUSTOMIZING THEMES">No Comments »</a></p> </div> <div class="post"> <h3 id="post-69"><a href="http://mysql5.premiumwebsitehosting.net/mysql5/chapter-5-adding-and-customizing-themes-167-web-hosting-support/" rel="bookmark" title="Permanent Link to CHAPTER 5 ADDING AND CUSTOMIZING THEMES 167 (Web hosting support)">CHAPTER 5 ADDING AND CUSTOMIZING THEMES 167 (Web hosting support)</a></h3> <small>Tuesday, May 1st, 2007</small> <div class="entry"> <p>CHAPTER 5 ADDING AND CUSTOMIZING THEMES 167 The node.tpl.phpfile presents a special case, as it is responsible for handling many types of nodes. Clearly, there will be cases where a blog should use a different template than a image or a poll. To support this, PHPTemplate lets you create templates specific to one node type by using a naming convention: node-type.tpl.php. For example, you might have node-book.tpl.phpand node-story.tpl.php for book and story nodes, respectively. Create one of these files in your theme s directory (in the same directory as page.tpl.php), and from then on, views of that particular node type will be passed on to the new template. Occasionally, modules will provide their own node template for the particular node type in question. An example of this is provided by the Organic Groups module, which was discussed in Chapter 4. Listing 5-5 shows the template file for group nodes. Notice that it is greatly simplified and leaves out many things that are not relevant for a group s node. Listing 5-5. node-og.tpl.php<br /> <div class="node<?php print ($sticky) ? " sticky" : ""; ?>“> <?php if ($page == 0): ?><br /> <h2><a href="<?php print $node_url ?>” title=”<?php print $title ?>“> <?php print $title ?></a></h2> <p> <?php endif; ?><br /> <div class="content"> <?php print $content ?> </div> </div> <p> Page.tpl.php The page.tpl.phpfile is the template that will handle calls to theme(’page’, $content). This call is the last thing that happens in the series of events leading up to a Drupal page being served. That places this template in the special position of defining the overall layout of the pages for your site. This is where you lay down the big picture. It also has the special distinction of being the only file that a PHPTemplate theme is required to provide. It is easily the most important and most complex of all the standard tpl.php files, as can be seen by the number of variables and the amount of code it contains. Table 5-8 lists the variables available in page.tpl.php. Table 5-8. Variables Available in page.tpl.php Variable Description $breadcrumb HTML that renders the breadcrumb links. $closure Normally contains client-side scripts that need to be included at the bottom of the page, thus is always the last thing to be printed before the closing </body> tag. $content HTML code of the central section of a page; the content that is unique to that particular page. $footer_message The text that was defined in the Footer Message field on the admin/settings page. $head HTML code generated by modules to be added to the <head> tag of the page. This typically includes tags for dynamically loading script files. Continued <br />Note: If you are looking for best quality webspace to host and run your tomcat application check Vision <a href="http://mysql5.premiumwebsitehosting.net">tomcat hosting</a> services </p> </div> <p class="postmetadata">Posted in <a href="http://mysql5.premiumwebsitehosting.net/category/mysql5/" title="View all posts in MySQL5" rel="category tag">MySQL5</a> | <a href="http://mysql5.premiumwebsitehosting.net/mysql5/chapter-5-adding-and-customizing-themes-167-web-hosting-support/#respond" title="Comment on CHAPTER 5 ADDING AND CUSTOMIZING THEMES 167 (Web hosting support)">No Comments »</a></p> </div> <div class="post"> <h3 id="post-68"><a href="http://mysql5.premiumwebsitehosting.net/mysql5/166-chapter-5-adding-and-customizing-web-hosting-domains-themes/" rel="bookmark" title="Permanent Link to 166 CHAPTER 5 ADDING AND CUSTOMIZING (Web hosting domains) THEMES">166 CHAPTER 5 ADDING AND CUSTOMIZING (Web hosting domains) THEMES</a></h3> <small>Tuesday, May 1st, 2007</small> <div class="entry"> <p>166 CHAPTER 5 ADDING AND CUSTOMIZING THEMES Table 5-7. Continued Variable Description $page A Boolean that indicates whether to display the node as a stand-alone page. If true, the theme does not need to display the title, because it will be provided by the menu system. $id An integer that uniquely identifies this node among all nodes on the page. $is_front A Boolean that is true if the page being generated is the site s front page. The default node.tpl.php template, shown in Listing 5-4, can be found at themes/ engines/phptemplate/node.tpl.php. Listing 5-4. Default node.tpl.php<br /> <div class="node<?php print ($sticky) ? " sticky" : ""; ?>“> <?php if ($page == 0): ?><br /> <h2><a href="<?php print $node_url ?>” title=”<?php print $title ?>“> <?php print $title ?></a></h2> <p> <?php endif; ?> <?php print $picture ?><br /> <div class="info"> <?php print $submitted ?><span class="terms"><?php print $terms ?></span> </div> <div class="content"> <?php print $content ?> </div> <p> <?php if ($links): ?> <?php if ($picture): ?> <br class='clear' /> <?php endif; ?><br /> <div class="links"><?php print $links ?></div> <p> <?php endif; ?> </div> <p> As you can see from the template code, the default node template makes three important decisions (highlighted in Listing 5-4): The first is whether or not this node is being displayed in a list as opposed to on a page by itself. This is done with the test <?php if ($page == 0): ?>. If it is in a list, $page will be zero, and the template is responsible for printing the node s title. On pages where the node is being displayed solo (node/nid), the node s title will be printed by the menu system, and the theme doesn t need to worry about it. The second decision concerns the node s links (such as add new comment), if present. The third decision involves printing the line <br class='clear' /> if there are not only links, but a user picture as well (the picture would have been printed earlier in the temve from breaking the layout. <br />Note: If you are looking for high quality webhost to host and run your jsp application check Vision <a href="http://linux.a1websitehosting.net">jsp web hosting</a> services </p> </div> <p class="postmetadata">Posted in <a href="http://mysql5.premiumwebsitehosting.net/category/mysql5/" title="View all posts in MySQL5" rel="category tag">MySQL5</a> | <a href="http://mysql5.premiumwebsitehosting.net/mysql5/166-chapter-5-adding-and-customizing-web-hosting-domains-themes/#respond" title="Comment on 166 CHAPTER 5 ADDING AND CUSTOMIZING (Web hosting domains) THEMES">No Comments »</a></p> </div> <div class="navigation"> <div class="alignleft"></div> <div class="alignright"></div> </div> </div> <div id="sidebar"> <ul> <li> <form method="get" id="searchform" action="http://mysql5.premiumwebsitehosting.net/"> <div><input type="text" value="" name="s" id="s" /> <input type="submit" id="searchsubmit" value="Search" /> </div> </form> </li> <!-- Author information is disabled per default. Uncomment and fill in your details if you want to use it. <li><h2>Author</h2> <p>A little something about you, the author. Nothing lengthy, just an overview.</p> </li> --> <li> <p>You are currently browsing the <a href="http://mysql5.premiumwebsitehosting.net/">Servlet Web Hosting - MySQL, Java, JSP, Servlet, Tomcat, SSH Blog</a> weblog archives for May, 2007.</p> </li> <li class="pagenav"><h2>Pages</h2><ul><li class="page_item"><a href="http://mysql5.premiumwebsitehosting.net/about/" title="About">About</a></li> </ul></li> <li><h2>Archives</h2> <ul> <li><a href='http://mysql5.premiumwebsitehosting.net/2008/04/' title='April 2008'>April 2008</a></li> <li><a href='http://mysql5.premiumwebsitehosting.net/2008/03/' title='March 2008'>March 2008</a></li> <li><a href='http://mysql5.premiumwebsitehosting.net/2008/02/' title='February 2008'>February 2008</a></li> <li><a href='http://mysql5.premiumwebsitehosting.net/2008/01/' title='January 2008'>January 2008</a></li> <li><a href='http://mysql5.premiumwebsitehosting.net/2007/12/' title='December 2007'>December 2007</a></li> <li><a href='http://mysql5.premiumwebsitehosting.net/2007/11/' title='November 2007'>November 2007</a></li> <li><a href='http://mysql5.premiumwebsitehosting.net/2007/10/' title='October 2007'>October 2007</a></li> <li><a href='http://mysql5.premiumwebsitehosting.net/2007/09/' title='September 2007'>September 2007</a></li> <li><a href='http://mysql5.premiumwebsitehosting.net/2007/08/' title='August 2007'>August 2007</a></li> <li><a href='http://mysql5.premiumwebsitehosting.net/2007/07/' title='July 2007'>July 2007</a></li> <li><a href='http://mysql5.premiumwebsitehosting.net/2007/05/' title='May 2007'>May 2007</a></li> <li><a href='http://mysql5.premiumwebsitehosting.net/2007/04/' title='April 2007'>April 2007</a></li> </ul> </li> <li><h2>Categories</h2> <ul> <li><a href="http://mysql5.premiumwebsitehosting.net/category/mysql5/" title="View all posts filed under MySQL5">MySQL5</a> (407) </li> </ul> </li> </ul> </div> <hr /> <div id="footer"> <!-- If you'd like to support WordPress, having the "powered by" link someone on your blog is the best way, it's our only promotion or advertising. --> <p> Servlet Web Hosting - MySQL, Java, JSP, Servlet, Tomcat, SSH Blog is proudly powered by <a href="http://www.visionwebhosting.net/">cheap hosting</a> <br /><a href="feed:http://mysql5.premiumwebsitehosting.net/feed/">Entries (RSS)</a> and <a href="feed:http://mysql5.premiumwebsitehosting.net/comments/feed/">Comments (RSS)</a>. <!-- 15 queries. 0.149 seconds. --> </p> </div> </div> <!-- Gorgeous design by Michael Heilemann - http://binarybonsai.com/kubrick/ --> </body> </html>