7 Theming in Drupal

1,307 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,307
On SlideShare
0
From Embeds
0
Number of Embeds
151
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

7 Theming in Drupal

  1. 1. Drupal theming<br />Wilson Wingston Sharon<br />wingston.sharon@gmail.com<br />
  2. 2. When you access a Drupal website, what you see on the screen is the result of the site's active theme files. <br />As the theme files call the data, the files also set the styling, position, and placement of the content on your screen. <br />
  3. 3. How a CMS functions - again<br />Text and pointers to other kinds of content are stored in the database; <br />that data is then dynamically retrieved, composed, and presented to a user in response to a request sent from a web browser. <br />Drupal functions with the themes playing the crucial role in the formatting and presentation of the contents<br />
  4. 4.
  5. 5. Remember<br />1. You Can Theme It All<br />The Drupal system allows you to specify different page templates for different purposes on your site. <br />2. Build with Blocks<br />The process of activating modules and assigning blocks to regions on the pages is one of the most basic and most important skills<br />Each of the blocks in the system, whether created by modules or manually created by the system administrator, can be themed individually, if you so desire.<br />3. Intercept and Override<br />
  6. 6. Intercept and override<br />several opportunities for you to affect the output prior to the data's arrival fron DB on the viewer's screen.<br />The best practice approach to customizing themes involves intercepting and overriding files and styles—not altering the core. <br /> By choosing to affect the system's output at the highest levels of Drupal's processes, we leave the core in a purer state. <br />
  7. 7. Files making up a theme<br />block.tpl.php – Defines the appearance of the blocks on the page.<br />box.tpl.php – Defines a specific format—a box used to frame things (like comments in the Bluemarine theme).<br />comment.tpl.php – Defines the appearance of the comments which follow items.<br />logo.png – An image file containing the logo used in the theme.<br />node.tpl.php – Defines the appearance of the nodes.<br />page.tpl.php – This is the primary theme file. style.css – The style sheet for this theme. <br />
  8. 8. Finding Themes online<br />Go to drupal.org themes section and download themes for your drupal version.<br />Do not use conflicting versions. Eg for drupal 6.x versions, download themes with 6.x in the file name.<br />Do not use alpha versions. Use beta ones at your own risk.<br />Download your theme. You’ll get it usually as a tar.gz<br />
  9. 9. Setting up themes<br />Remember the sites/all/modules folder where we put the downloaded modules?<br />Go to c:/wamp/www/mysite/sites/all and make a folder called themes.<br />Extract your theme into that folder.<br />Go to administer>>themes<br />Click the radio box for default on theme you like and click ok.<br />
  10. 10. configure<br />Click the configure link, make sure you are on global settings.<br />Here, you can set up theme options for all themes you might have. These override individual theme options.<br />Now click on the theme links you see, all enabled themes show up as a link and you can give them individual settings too.<br />Some themes have a lot of individual settings that you can exploit.<br />
  11. 11. Zen<br />Zen is the ultimate starting theme for Drupal. If you are building your own standards-compliant theme, you will find it much easier to start with Zen<br />Support: Providing or receiving support for any theme you develop in Drupal’s normal support forums can be difficult.<br />Bug fixes & updates: Occasionally there will be bugs found in Zen core. If you have modified any of Zen’s core files, it will be difficult for you to incorporate any of those bug fixes into your modified version of Zen.<br />
  12. 12. Theming trick –Create a custom user login bar<br />Display a compact, nice user login form that can fit in one line.<br />Once user is logged in, It will display a welcome message and a couple of helpful links.<br />We’ll do this in the garland theme. So go to admin>>themes and move back to garland.<br />Garland files will be in c:.mysite hemesgarland<br />
  13. 13. Approach<br />Drupal is very powerful, it's so flexible that you have many ways to do things. That's why a 5 minutes of thinking is very recommended before we get our hands dirty.<br />a separate function, call it garland_user_bar(). It decide, and return HTML for the login form, or the welcome message.<br />page.tpl.php, we will place a call to this function somewhere where it gets displayed in the top.<br />Now we have the logic, after that we will write some CSS to style it, to change how it looks<br />
  14. 14. Open the folder styling files. You can copy paste code from here to where I tell you.<br />First open the page.tpl.php from garland root theme folder.<br />Add <div id="navigation"><?php print garland_user_bar() ?></div> from 1. page.tpl.code on line 16, just under the body tag. Save and close.<br />
  15. 15. Adding the php function<br />Open themes/garland/template.php <br />Append the contents of 2.template.php.txt I provided to the end of this file.<br />function garland_user_bar() {  global $user;                                                                  $output = '';  if (!$user->uid) {                                                               $output .= drupal_get_form('user_login_block');                              }                                                                              else {                                                                           $output .= t('<p class="user-info">Hi !user, welcome back.</p>', array('!user' => theme('username', $user)));       $output .= theme('item_list', array(      l(t('Your account'), 'user/'.$user->uid, array('title' => t('Edit your account'))),      l(t('Sign out'), 'logout')));  }      $output = '<div id="user-bar">'.$output.'</div>';  return $output;}<br />
  16. 16. styling<br />Open themes/garland/page.tpl.php<br />Add contents of “3.stylecode.txt” after line 15, before the </head tag.<br /><style type="text/css" media="all">@import "<?php print base_path() . path_to_theme() ?>/user_bar.css";</style><br />Copy user_bar.css into the garland theme root.<br />
  17. 17. Wingston.sharon@gmail.com<br />www.workshopindia.com<br />workshopindia@gmail.com<br />queries@workshopindia.com<br />

×