tags:

views:

1390

answers:

18

Just wondering what tips or tricks you guys might have to share. As always with posts like this, please only one tip per post so they can be voted on independently.

I'll start: however you do your theming, you can use the mothership theme as a base theme for your theme to inherit from so that your markup will be a lot cleaner and less verbose.

+2  A: 

I heard of people using internationalization features to change bits of text that they otherwise couldn't.

Ollie Saunders
The stringoverrides module is awesome for that. I use it all the time for stuff that's been hardcoded into modules.
Mike Crittenden
+6  A: 

learn the views module in and out

Scott M.
+5  A: 

Use the backup and migrate module its helps you a lot.

Geshan
+3  A: 

The most powerful feature in Drupal, is it altering system. This manifests in two ways

  • The entire theming system
  • drupal_alter() (most commenly seens as hook_form_alter)

The reason why these things are so powerful, is that it enables you to alter drupal core functionality and alter how drupal renders different things without changing drupal core itself (or contributed modules).

This is probably one of the major reasons to Drupal's success, since it allows developers to customize Drupal to do exactly what they want, and still retain all of the progress being made to Drupal and contributed modules.

googletorp
+8  A: 

Before coding any custom feature in Drupal, make sure there isn't already a module for it.

Jeremy French
So true. Nothing is more of a letdown then coding some awesome module or what not, wanting to submit it, and then realizing that there's already something available online that not only does what your feature does, but usually does it better. Not that I would know anything about that *cough* *cough*
canadiancreed
+1  A: 

Use the $id variable in node.tpl.php to make themes allow things other than long vertical lists of content. For example, you could check whether $id is 1, and if so wrap the node in a div which puts it in a big highlight zone at the top right of the page. (This is useful when combined with the 'make sticky at top of lists' function.) Then you could have two columns some way lower down the page, containing $ids between 2 and 8 and 9 and 15.

Sometimes you might need to check something other than the $id number to determine which 'zone' to place a node into. In this case, it can be very helpful to do some of the checking in a hook_preprocess_node function (which you can place in your template.php file as themename_preprocess_node) which contains a static variable which you can use to store the result of checks on nodes which have already been shown on the page. For example, I use this to display a date heading above nodes providing a node of that date has not already been shown, like so:

if ($vars['teaser']) {
  static  $last_date;
  $date = format_date($node->created, 'custom', 'l jS F');
  if  ( $date != $last_date ) {
    $vars['show_date'] = TRUE;
    $last_date =  $date;
  }
  else {
    $vars['show_date'] = FALSE;
  }
}
tog22
+12  A: 
  • Use the zen theme - not only it makes theming easier, it also adds CSS classes that reflect the state of the website (like <body class="not-front not-logged-in page-node node-type-project-project two-sidebars">) - makes it really easy to customize your site.

  • Browse through Drupal Modules - 9 out of 10 chances you'll find what you are looking for there - is it safe and/or maintained - that is a different question ;) But at least you'll have a starting point.

Igor Klimer
The Starkish theme is nice because it uses all the cool contextual classes of Zen but without all the extra markup and CSS.
Mike Crittenden
+1 for the zen theme - it makes life so much easier.
threecheeseopera
Thanks for the info on the Starkish theme - seems like a great alternative to zen (I'm used to zen and love it, but some might like Starkish better).
Igor Klimer
+5  A: 

When setting up a new site, we immediately create a blank custom module named after the site/project. This becomes the central place where to put all the small fixes/kludges/tweaks that pop up to solve all those minor change requests that are not really features and do not call for a full blown module (at first ;) - this module should be regularly reviewed and refactored to remove stuff that became obsolete or to pull out stuff that turned into a feature, thus deserving a full module on its own.

Same for themes - whatever theme we start our sites with, usually it will get modified quickly/immediately, so best to rename it to the site/project from the beginning.

The 'site module' complements the 'site theme', in that it contains the business/workflow/data related tweaks/manipulations that otherwise would end up cluttering the themes template.php file (which should really only contain theme specific stuff).

Henrik Opel
+1  A: 

Using /var/www for my web root, I create /var/www/sites and symlink my sites directory to it, and /var/www/files for robots.txt. It makes upgrading (in the absence of an SCM) less scary, just overwrite the /var/www/drupal folder with the new version and hit update.php.

Use a local copy of drupal for your development; it's much less of a pain to debug locally than over the WAN, and easier for you to use your site's code as a project in your IDE, which (may or may not, dep. on your IDE) provide you with code completion and easy access to your files. When you're done you can push the changes via ftp/scp, or using whatever SCM you are familiar with.

I use devel's dsm() function liberally, so i would recommend that module. It makes debugging-without-a-debugger (i.e. after prod. move) much less painful.

Also, Admin Menu makes administering your site much easier; it gives you dhtml popup menu access to all the admin pages, in a hierarchy, so there's only one click between you and most admin functions.

threecheeseopera
+10  A: 

use drush to install/update modules and do maintenance tasks. if you use drupal you cannot go without it.

gpilotino
What specific benefits does drush offer for module upgrades? I am looking to simplify maintenance of several sites :)
NPC
it's faster to try it than to ask ;) anyway, you can upgrade everything without the tedious task of going to drupal site, downloading the module, untar etc.
gpilotino
+2  A: 

Install and use the devel module. Spend some time with it up front have a more intimate knowledge of how it can help you debug modules, theme development, etc.

Mike Munroe
A: 

Panels3

Learn it, use it, master it. It makes your site highly dynamic.

Zachary
+3  A: 

I shared some tips in this presentation

http://www.slideshare.net/mirnazim/best-practices-for-drupal-developers-by-mir-nazim-drupal-camp-india-2008.

Note: Fonts in slideshare are F***ed up, its better to download.

mirnazim
+5  A: 

Two pieces of advice:

Don't blindly use the first module that shares a name with what you want it to do. Often the first module "captures" the namespace for that feature, but another, less aptly named module will fulfill the functionality better.

Look around for a way to do what you want that includes CCK/Views integration. This is pretty apparently the future of Drupal, so a standalone module that does what you want it to do that competes with a views/CCK-dependent module will probably die out in the near future.

++ to Geshan's suggestion.

Michael Morisy
+2  A: 

CCK + Views + Panels

Toktik
+1  A: 

Framework is another great module for beginning the development of a theme. Using it as a base theme, I was able to port an existing theme to Drupal within hours.

ford
Agreed, this is an excellent theme to start with if you know what you want from your html/css (and even if you don't, I am guessing, though I usually do :)).
NPC
A: 

Use exportables, via ctools module or the built in ones for views, etc to get key configuration settings outside of the database and put them into version control. This will make moving updates and changes from one site to another a lot easier.

A: 

If you're not stuck with PHP5 or a non-mysql database, use Pressflow (http://pressflow.org) instead of stock Drupal. Pressflow is optimized for mysql+php5 and supports better caching setups as your site grows, such as putting Varnish in front of Drupal for anonymous users.

related questions