background image
HomeRecent PostsDrupalSearchTagsRSSContactAboutAccount
Eric.London's picture
  • Most importantly, read all the documentation
  • Second most important, learn when to use a preprocess function versus a template file. The Devel module's Theme Information will help determine the name of core template suggestions and preprocess functions
  • Put your code in a preprocess functions, your html in tpl.php files, and your CSS in a style sheet. Avoid mixing these files when possible. Following the rules of MVC frameworks will help promote flexible and clean code
  • Before creating a new template file (or preprocess function), see if the theme can be adjusted using: 1) a configuration change (for example, changing a view's layout); or 2) simply adding or modifying CSS
  • If you find yourself reusing code, create a function in template.php to promote consistency
  • Include javascript and style sheets conditionally to improve performance and reduce overhead
  • Avoid using inline style or javascript. Put CSS in a style sheet; and use drupal_add_js() to include javascript
  • When creating new template files, be sure to register them in hook_theme() and use the theme() function to call them
  • When creating a new tpl.php template file, make sure to include the same variables used in the default template, or you might be missing something in your theme (tabs, title, help, etc).
  • When defining new variables in a preprocess function, prefix the variable names with a common identifier so you call easily tell your custom variables apart from the Drupal default variables.
  • When theming a view, take advantage of the "Theme: Information" link under basic settings to help determine the right template file to use. For instance, if you want to modify the output for a single field, don't create a views-view.tpl.php file; use a views-view-field.tpl.php file instead
  • Keep scalability in mind at all times. For instance, when theming a view, will your code break if the admin switches from a page layout to a block layout? Also, try to avoid setting a fixed height on regions, there is no telling how many content items & blocks the user will attempt to assign to a region.
  • When creating regions and columns in your theme, test for their contents before displaying them. If your regions do not have any blocks assigned, you can increase the size of your main column/region and avoid large areas of awkward white space.
  • When theming a menu block in a region, user CSS selectors specific to the region (not the block). That way when you assign another menu to the same region, you will not have to replicate the CSS for the menu block.
  • Modify forms using hook_form_alter() when possible
  • Use file versioning software like Subversion to track and deploy your theme edits
  • NOTE: more tips coming soon, please check back again.
Syndicate content