Drupal 7 theming cookbook

364 398 2
Drupal 7 theming cookbook

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

làm quen theme trên drupal

Drupal 7 Theming Cookbook Over 95 recipes that cover all aspects of customizing and developing unique Drupal themes Karthik Kumar BIRMINGHAM - MUMBAI Drupal 7 Theming Cookbook Copyright © 2012 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First Edition: November 2010 Second Edition: January 2012 Production Reference: 1100112 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84951-676-1 www.packtpub.com Cover Image by Karthik Kumar Credits Author Karthik Kumar Reviewers Kevin Davison Richard Eriksson Acquisition Editor Sarah Cullington Lead Technical Editor Hyacintha D'Souza Technical Editors Joyslita D'Souza Apoorva Bolar Arun Nadar Ajay Shanker Project Coordinator Alka Nayak Proofreader Julie Jackson Indexers Monica Ajmera Mehta Tejal Daruwale Rekha Nair Graphics Conidon Miranda Production Coordinator Nilesh R. Mohite Cover Work Nilesh R. Mohite About the Author Karthik Kumar is a Drupal developer residing in Chennai, India. He rst came across Drupal in late 2004 and has been a fan ever since. He maintains a number of modules on http://drupal.org under the moniker Zen, http://drupal.org/user/21209 , and has also made substantial contributions towards the development of Drupal core. To my reviewers, Kevin Davison and Richard Eriksson, for their careful scrutiny. To all the people at Packt involved in the making of this book—Sarah Cullington, Hyacintha D'Souza, Joyslita D'Souza, and Alka Nayak—for their guidance and patience. To Dries and the Drupal developer community for making Drupal what it is today. Finally, this book is dedicated to my parents for all the freedom that they have given me. About the Reviewers Kevin Davison is a Manager, Web Generalist, Drupaler at Quevin, LLC in San Francisco, CA. Experience with Drupal began as an experiment on Quevin.com , and it has evolved to become his passion. You can nd Kevin actively involved at many DrupalCon's, Camps, SFDUG, Drupal.org support, @Quevin, and with the Drupal community on IRC (Quevin). Quevin (kweh-vin)—the business—stands for its effective methods of planning, designing, and developing exceptional Drupal-based websites. Quevin is a full-service web production team, with a single managing director who is available to speak with you directly. He was the Technical Reviewer for the last version of this book, Drupal 6 Theming Cookbook . Thanks to the Drupal community for making all of this possible and to Dries for having the vision. Packt Publishing has made this a great learning opportunity. Richard Eriksson has been a member of the Drupal community since 2004 (visit his prole at http://drupal.org/user/8791 ). He has worked on the Community Support and Systems Administration team at Bryght, the rst commercial Drupal venture (later purchased by Raincity Studios), and later at OpenRoadCommunications, where he helped build video-intensive multilingual Drupal websites promoting video games. He also maintains an independent consultancy called Ethical Detergent specializing in Drupal maintenance and support. On Drupal.org , he maintains the Pirate and RSS Permissions modules, the Cherry Blossom Theme, and most recently, the Readability Button module. He writes occasionally on his blog, Just a Gwai Lo ( http://justagwailo.com/ ). www.PacktPub.com Support les, eBooks, discount offers and more You might want to visit www.PacktPub.com for support les and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub les available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details. At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why Subscribe? f Fully searchable across every book published by Packt f Copy and paste, print and bookmark content f On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com , you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Drupal Theme Basics 7 Introduction 7 Installing and enabling a theme 10 Uploading a new logo 13 Uploading a new favicon 15 Adding a slogan to the theme 17 Displaying a different theme for administration 20 Adding an existing block to the theme 22 Adding a custom block to the theme 24 Displaying a block only on the front page 27 Controlling block visibility based on user role 30 Controlling block visibility based on node type 31 Chapter 2: Beyond the Basics 35 Introduction 35 Understanding the anatomy of a theme 36 Creating a subtheme based on a core theme 38 Overriding base theme elements in a subtheme 41 Changing the screenshot image of a theme 45 Including a CSS le in a theme 48 Enabling CSS optimization 50 Creating the mysite module to hold our tweaks 54 Adding a CSS le from a module 56 Displaying a different theme for each day of the week 59 Creating a fresh look using the Color module 61 Chapter 3: Custom Themes and Zen 65 Introduction 65 Clearing the theme registry 67 ii Table of Contents Creating a theme from scratch 69 Creating myzen—a Zen-based theme 72 Choosing a CSS layout for myzen 75 Overriding Zen template les with myzen 77 Adding a custom region to myzen 80 Adding a background image to the theme 84 Adding a conditional stylesheet in Zen 87 Modifying myzen's theme settings 89 Chapter 4: Templating Basics 93 Introduction 93 Changing the structure of a page using template les 95 Customizing the appearance of a particular node type 98 Customizing the appearance of a specic node 102 Theming made easy using the Devel module 106 Theme overrides using the Theme developer module 108 Styling the site maintenance page 111 Chapter 5: Development and Debugging Tools 113 Introduction 113 Finding the right function to use to theme an object 115 Analyzing variables using the Devel module 118 Generating sample content using the Devel generate module 120 Resetting the default theme manually 122 Live preview with Web Developer 124 Validating HTML and CSS using 127 Web Developer 127 Turning off JavaScript in the browser 129 Disabling CSS in the browser 131 Inspecting elements and debugging CSS using Firebug 134 Diagnostic logging of JavaScript using Firebug 137 Chapter 6: Advanced Templating 141 Introduction 141 Adding a variable to all node templates 143 Deleting a variable from the page template 146 Adding a custom theme setting 149 Hiding all regions on a page 151 Displaying the last updated date instead of the submitted date 155 Module-based variable manipulation 158 Optimizing using hook_preprocess() 160 Displaying the date eld in calendar form 164 iii Table of Contents Chapter 7: JavaScript in Themes 167 Introduction 167 Including JavaScript les from a theme 169 Including a JavaScript le only for certain pages 171 Giving the username texteld keyboard focus 174 Exporting a variable from PHP to JavaScript 177 Adding default text to the search texteld 179 Displaying comments in compact form 182 Minimizing and maximizing blocks using JavaScript 185 Chapter 8: Navigation 189 Introduction 189 Adding a menu to our theme 190 Adding content pages to the menu 193 Styling the Main menu 195 Contextual submenus using the Menu module 199 Adding a drop-down navigation menu 203 Customizing breadcrumbs in Zen-based themes 207 Hiding node links using CSS 209 Styling all external links in a page 211 Styling the Drupal pager 213 Chapter 9: Form Design 219 Introduction 219 Finding the form ID of a form 220 Changing the height of a textarea 223 Replacing Drupal's textareas with a WYSIWYG HTML editor 226 Reorganizing elds in a form 229 Replacing a standard submit button with an image button 232 Styling the comment form 235 Using a eldset to group elds 240 Theming form elements from a module 245 Adding class attributes to form elements 248 Chapter 10: Theming Fields 253 Introduction 253 Creating a new node type 254 Displaying elds together using eldgroups 259 Manipulating display layouts using eldgroups 262 Theming a eld using a template le 265 Adding image elds using the Image module 269 Using Image styles to scale and crop images on the y 272 Adding lightbox support for images 275 [...]... a panel iv 279 281 2 87 294 299 306 315 3 17 321 324 3 27 331 334 339 Preface Themes are among the most powerful and flexible features available when it comes to the presentation of a website The greatest strength of Drupal lies in its design, which, when done correctly, allows developers and designers to customize and micromanage each and every aspect of the site Furthermore, the Drupal theming system... customize various theme elements Chapter 7, JavaScript in Themes, covers the use of JavaScript and jQuery in Drupal themes Chapter 8, Navigation, contains recipes which focus on theming navigational elements in a Drupal theme, such as menus, breadcrumbs, pagers, and so on Chapter 9, Form Design, discusses the Drupal Forms API from a theming point of view Chapter 10, Theming Fields, demonstrates how to theme... available at http:/ /drupal. org/ requirements Since this book deals with theming, it is assumed that this test site is already up and running 2 Preface Who this book is for This book is written for Drupal developers who want to refresh the look and feel of their sites If you are a Drupal site administrator who is looking to go beyond the basics and customize the presentational aspects of your Drupal site,... Views Theming, focuses on the Views module from a themer's perspective Chapter 12, Rapid Layouts with Panel, shows how to create complex layouts using the Panels module and demonstrates its use in conjunction with the Fields API and Views modules What you need for this book A standard Drupal 7 development site is all that is required to run through the recipes in this book The system requirements for Drupal. .. see if bugs have been reported and are being addressed in a timely manner Git is a tool used by Drupal developers to manage their code and control their releases It is effectively a repository for modules, themes, and Drupal itself More information on Git is available at http:/ /drupal. org/handbook/ git 9 Drupal Theme Basics Once the list of candidate themes has been narrowed down to a short list, the... Every time a page is displayed, Drupal checks to see if the URL of the page begins with admin If it does and if we have specified an administration theme, Drupal overrides the default theme being used with the specified theme Since the administration theme is a special case, Drupal does not require the theme to be enabled for it to be available as an option See also Just as Drupal can dynamically change... file, which registers the theme with Drupal, to tpl.php template files accompanied by CSS, JavaScript, and other files that determine the layout and style of the content Depending on the nature of the site and its requirements, developers can choose from the slew of themes available on http:/ /drupal. org as contributed themes or instead, decide to roll their own Drupal Theme Basics Contributed themes... estate The question of which to use is generally decided on a case by case basis The Drupal theme system also supports the use of different theme engines to render the design Each engine uses a different process by which the designer can interact with Drupal to implement a design The PHPTemplate engine is built into Drupal and is by far the most popular of the ones available The vast majority of contributed... need to be performed, and in some cases, specify if the recipe builds on the result of earlier recipes in the same chapter Preface What this book covers Chapter 1, Drupal Theme Basics, introduces the reader to the basic elements of Drupal theming, such as downloading and installing a contributed theme, and learning how to add and customize blocks Chapter 2, Beyond the Basics, explains the concept of... usually offers superior compression These files can be extracted using archive programs such as 7- Zip (http://www .7- zip.org) as well as commercial packages such as WinZip (http://www.winzip.com) and WinRAR (http://www.rarlabs.com) How to do it To install a theme, open Windows Explorer and navigate to the Drupal installation: 1 Browse to sites/all/themes 2 Extract the downloaded theme into a subfolder . Drupal 7 Theming Cookbook Over 95 recipes that cover all aspects of customizing and developing unique Drupal themes Karthik Kumar. images 275 iv Table of Contents Chapter 11: Views Theming 279 Introduction 279 Creating a simple View 281 Styling a node listing using a Grid display 2 87 Embedding

Ngày đăng: 02/07/2013, 15:31

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan