Posted on November 19, 2007 // Short URL

50 Drupal Tips and Tricks

The Lullabot team celebrates its 50th podcast with a list of 50 Drupal tips and tricks.

Here's the list:

Drupal admin and configuration:

  1. Create a "HTML help" block and assign it to appear on only "node/*/edit" and "node/add/*"
  2. Use the "edit permissions" link on admin/user/roles to get a single column
  3. Use the Firefox Web Developer Toolbar to "Populate Form Fields" on the access page for the admin role
  4. Use "site:drupal.org {search terms}" to search all of drupal.org with
    Google. Set up a Firefox shortcut so you can type "dru [your search]" to
    search Drupal. Also api.drupal.org/apis/{search_term}
  5. When using pathauto to alias usernames, don't let users change their usernames.
  6. Use PathAuto and Path Redirect together to redirect old aliases to the new ones. Search engines will love you.
  7. Use Global Redirect to make sure home page is "/" and current page doesn't have an alias.
  8. When creating PathAuto template, keep uniqueness in mind -- perhaps add a date to your blog and news entries.
  9. Move the "My Account" menu item by creating a custom menu item at 'user'
  10. Use update_status module along with cvs_deploy & cvs tags to manage sites
  11. Use ImageCache to resize images. It's worth the poor u.i. and configuration challenges. Tastes best with ImageField, CCK, and Views.
  12. Turn any CCK type with an imagefield into a photocast with ConTemplate
  13. Use Automatic Node Titles whenever you want to have separate (CCK) fields for first name and last name, but you want the node title to contain the full name.
  14. Use SimpleMenu to remove the need for an admin block on the page.
  15. Set your site in "offline mode" when doing Drupal upgrades, to ensure that your end users are never exposed to any funky errors.
  16. Use locale.module to change English text into other English text. Example: change "Forums" to "Message Boards". Slight performance issue for high-traffic sites. In Drupal 6, there's a new "locale lite" feature to translate only a few pieces of interface text without the overhead of locale module itself. Check the bottom of default.settings.php for more details.
  17. Use views + views_fastsearch to build "section search" or custom advanced search pages

Drupal.org

  1. Enable the contributor block on drupal.org. This will give you access to all kinds of useful links, as well as tell you how close we are to releasing Drupal 6.
  2. Check out the Drupal Planet at http://drupal.org/planet to keep up to date on exciting developments and what various folks are working on.
  3. Post suggestions or bugs you find with Drupal or contributed modules to the issue queues, not on the forums. They're much more likely to get attention from developers there.
  4. Check out http://drupal.org/node/10259 for some tips on posting to the issue queue, including how to make a good bug report/feature request, how patches get reviewed, and so on.
  5. Head to http://drupal.org/videocasts to view a categorized archive of various Drupal videos and presentations on a variety of subjects.
  6. Sign up for the security announcements at http://drupal.org/security to keep on top of your updates!

  7. Ninja search #1: Negative words. Eliminate the words you don't want with a minus in front: -Joomla

    Ninja search #2: Content types: type:forum or type:image etc.

    Ninja search #3: Phrase search. Put exact phrases in "", as in "Drupal rocks".

Theming

  1. Set up a quick "wireframe" site using Zen or another simple theme. Show this and the HTML it outputs to your web designer before they start working. Point out items like tabs and messages.
  2. Change your administration theme when working on a new theme
  3. Get to know Firebug for ALL front-end development: JavaScript and CSS!
  4. <?php
    var_dump
    (get_defined_vars());
    ?>
    inside any template file to see what variables are available.
  5. Create a hook_link_alter() and add a "More..." link to the end of the Teaser text while removing the Read more link
  6. The format_interval() function
    is cool. It outputs "X minutes Y seconds ago", or similar...
  7. Accommodate page caching by substituting dynamic page elements in your theme.
    If the user is not logged in, use absolute values such as "posted on {date}
    at {time}", rather than relative such as "{X} hours, {Y} seconds ago".

Views

  1. Use theme('view', {arguments}) to embed a view anywhere in your theme's template.php or .tpl.php files
  2. Use the custom argument handling code in a View to change anything about a view: filters, number displayed, fields, and of course arguments. You can alter these items with or without conditionals. Change the number of columns in a grid view; change the number of items that appear if the "feed" argument is present; etc... (see #36 to see the view object)
  3. Use "promote to front page" / "sticky" to do other things using Views... see also Views Bookmarks
  4. Use Views + Taxonomy
    Redirect
    to use a custom view for each vocabulary's listing pages.
  5. Use print_r($view) inside the 'Argument code' field of a View to see the view object. see #33 (oops)

  6. Give any number of 'block'-only views the same page URL, and their [more] links will all point to the same page.

JavaScript

  1. Translate your javascript by doing

    <?php
    drupal_add_js
    (array('my_module' => array('my_string' => t('My string'))), 'setting')
    ?>
    Get translated strings from javascript: Drupal.settings.my_module.mystring
  2. Same with urls:
    <?php
    drupal_add_js
    (array('my_module' => array('my_url' => url('node/10'))), 'setting')
    ?>
    It's more reliable and less work than using $base_path and Clean URL setting.

Drupal Development and Coding

  1. DON'T HACK DRUPAL
  2. Many IDEs (Zend, Komodo, Eclipse) will parse Drupal's code base and give you autocomplete and documentation on the function names
  3. Run a local copy of api.drupal.org (using api.module) -- parse contrib modules! Documentation here: http://drupal.org/node/26669
  4. Figure out arg(), you won't be sorry.
  5. Use $_GET['q'] anywhere in your site to get the real Drupal path (not what's in the menu bar)
  6. Find out if the current user is logged in:
    <?php
    if ($GLOBALS['user']->uid) {/* the user is logged in */}
    ?>
  7. In Drupal 6, the contrib Schema module will generate a full-documented list of Drupal's tables. See http://jaspan.com/drupal-6s-self-documenting-database-schema and http://drupal.org/node/184586.
  8. Use cvs annotate to track down the hows and whys of a particular line of code. View a how-to at  http://www.lullabot.com/articles/cvs_annotate_or_what_the_heck_were_they_thinking
  9. Coder module can not only be used to check over code for coding standards compliance, but can also be used to notify you of things that need to be done to your module to upgrade it to the next Drupal version.
  10. On api.drupal.org, you can use the "List references" tab on any function to view where else in the source it's called, as well as what other functions are called by the function you're looking at. This can be helpful if you have a question about how a function is used.

  11. Drush!

Comments

theBorg

Happy aniversary!

Happy anniversary!

Wow!, this is going to be the Great one, thanks.

Reply

Rowan

Pause button

I had to disable images for lullabot.com so I could click the pause button. :/

Reply

yaph

You can also download the

You can also download the complete podcast as an mp3 file and play it form your local hard disc hopefully without problems hitting the pause button.

Reply

Dave Myburgh

Awesome tips!!

Once again, a great podcast. There are some really fantastic tips in this list - my favourite is the local api website setup. So often I am developing without an internet connection, so this will really help me out. Thanks! I'm bookmarking this page for future reference, as there are so many great tips here, its going to take me a while to investigate all of them.

One tip I can give you guys is an alternative to the SimpleMenu module, and that is admin_menu. It uses just CSS to provide a drop-down list of all admin menu items. Very cool.

Reply

Joe Chellman

Tasty tips

Thanks for these. The tip on moving around /user seems so obvious now that I've heard it. hook_link_alter is also immediately useful to me — I just implemented a change to comment_link this way. Woo!

For what it's worth, var_dump() gives you a bit more information about a variable, like how long strings are and that kind of stuff. print_r leaves that extra information out to make things a bit more readable. That's my understanding, anyway.

On the Firefox shortcut tip, for Mac users using Camino, these are called Bookmarks Shortcuts. I love these things to death. Here are two I use all the time:

d - http://api.drupal.org/api/search/5/%s (forces an API search on version 5)
dp - http://drupal.org/project/%s (go straight to a project page)

Reply

Ben McRedmond

Re: Firebug

Hey, Great podcast. Re: Firebug in the new safari 3.0 included with leopard the web inspector tool is greatly improved.

defaults write com.apple.Safari IncludeDebugMenu 1

Run the above command in terminal, to enable it. Restart safari and right click on any web page "Inspect Element" or go to the "Debug" menu and choose "Select Web Inspector". This can be docked to the bottom of the page like firebug (see little buttons at bottom of sidebar), it has almost all the same features. I'm not going back to firefox.

Reply

romand

tip 29

Thanks for this article!
Please explain tip 29 (may be short example)?

Reply

Gordon Heydon

Some of my hints.

Instead of using drupal_get_path_alias() to get the alias of the current page, you can use $_REQUEST['q']

If you want the real path of the current page then you can use $_GET['q'].

Also for views the search is included by default, so you don't need to install fastsearch. But fast search will give you more options.

Reply

Rob Loach

"My Account" Menu Item

You guys were asking if with the menu system in Drupal 6, you can move "My account"... Well, you can! And by dragging and dropping! Yay!

Reply

tommo

pretty print_r

In the podcast it says look at the source to see the formatted version of the output if you use print_r (amazingly useful function). If you put it inside a pre tag then the print_r function output will be formatted within the browser too.
eg:

<?php
 
print('<pre>');
 
print_r($vars);
  print(
'</pre>');
?>
Reply

jeff

Devel Module functions

If you have Devel Module installed (and enabled), it provides several functions for pretty printing. Good functions are dpr() and dvr() which check to see that the user has admin permissions and then do a <pre> wrapped print_r() and var_dump() respectively. This means that non-admin users won't see the "goop" when you're working on the live site. But of course, you're not working on the live site are you?!? ;-) Better yet are the dpm() and dvm() functions which put their output into Drupal's $messages output for your theme. This keeps the output from printing before the HTML and making many themes go nuts. It's too late in the page life cycle to use dpm() and dvm() in page.tpl.php or the 'page' case of _phptemplate_variables() (the output won't show up 'til the next page load), but they're pretty groovy used anywhere else!

Reply

uberEllis

HelpTip module

One of the often overlooked modules I use in every site I release, is HelpTip (might be because it's never really progressed beyond a development release for Drupal 5).

Perfect for Tip #1, while giving the user the extra choice of not seeing the same helptip again.

If, like me, you use a base database for every project, Help Tip saves a lot of time on initial "How To" emails for new clients et al (I'll get my head around install profiles one day... I promise)

Reply

dschmid

Number of Grid View Columns

Hello, you have posted that it's possible with the custom argument handling code in a view to change the number of columns. I can't figure out how to do that. I want in one view with only three instead of four columns. How that works? Thanks for any help or links.

Reply

Michael

Archival Podcasts?

The tips and information on this site is amazing, especially while still learning so much about Drupal. Is there any way to get an archival podcast feed so that those new to here can get the podcasts in a much cleaner and informative list instead of just downloading LullabotPodcastNoXX.mp3 into folders? It'd be a huge help!

Reply

Linulo

Awesome!

The Lullabot podcasts are always good and interesting, but this one.. wow! Sooo useful! Even for the ones I have heard about before it is a reminder that I should not forget about them simply because they make life so much easier. Even the "developy" tips that cannot be explained well in a podcast serve as excellent pointers.

Thank you very much indeed, Angie, James and Jeffs! Please clone yourself and let the clones make a Screencast of every single tip ;-).

Reply

Ivan mejia

Great tips

but please keep music down, the volumen is so high!! so the music fight with the voice :( and please dont use enya hehe.

Reply

robert

Music: From 00:05 to 00:35?

Are you referring to the Lullabot podcast themesong which plays for 30 seconds in the beginning? It does go away after the first 30 seconds, so if you heard Enya, it was coming from some other source. The podcast themesong was written and performed by Jeff Robbins.

Reply

Benjamin MelanÃ...

Use drupal_set_message with print_r to see the view code

Specifically, put this in the custom argument code:

drupal_set_message('<pre>' . print_r($view, TRUE) . '</pre>');

To do this on a live site without regular folks seeing, while you're online as user #1, you can use this:

global $user; if ($user->uid==1) drupal_set_message('<pre>' . print_r($view, TRUE) . '</pre>');

(Note: Agaric Design Collective would never, ever, ever do debugging or development on live site. Ever. Well maybe sometimes.)

I'm glad jochen said print_r didn't work for him either. It must be called so deep in Views code it doesn't show up!<

Reply

Thomasr976

Partititioning your Podcasts into small sessions

I really like your podcasts and intend to listen to them all. Recently I received an Apple Ipod shuffle and download this podcast and others. Problem is that when I push the button to go to the next podcast, it takes an eternity and I ahve to listen to see when I am on the next podcasts.

Possible Solution: Can you all think about doing the following:

1) Give users upfront an itinerary of when subjects will be discussed. For example, "in the first 15 minutes we will discuss all 17 Drupal admin and configuration tips." In the next 15 minute segment we will discuss, Drupal.org tips, etc etc

2) Ideally, create a unique podcast for each major section of the podcast, i.e. tips for Drupal admin and configuration, then another for Drupal.org, views, theming, etc.

I think this would really be appreciated by the community and really go along way to achieve your goals of educating and entertaining novice and seasoned drupal users as well. Thanks for giving this some thought, have a Happy New Year

Reply

Amnon Levav

Full text summary - let's make it a tradition.

It's great that this podcast is having a full textual summary - please make it a tradition.

I really like your podcasts, but sometimes they are very length and I find it very much more practical to read the text when I am in front of the computer.

Also, it might be possible to create a table of contents for the main subjects discussed, e.g. (Minutes:Seconds):
0:30 - Intro and General news
12:17 - Taxonomy context
15:30 - Taxonomy breadcrumb

Then people will be able to start listening from the exact minute, yet download the whole podcast.

Amnon

Reply

NonProfit

Tip 25 Rocks!

Hey, I'm really digging tip #25, "Set up a wireframe & show the HTML output to your web designer." Any links on how to best utilize this? What should be included? Thanks! -NP

Reply

Amnon Levav

When does each tip starts?

This is a great podcast. But what if you need to jump to a specific tip?
Here is the exact times when each tip starts:

Drupal admin & Config trips
#1 - 6:15, #2 - 8:00, #3 - 8:45, #4 - 10:15, #5 - 12:12, #6 - 13:10, #7 - 13:50, #8 - 15:30, #9 - 16:40, #10 - 17:50, #11 - 19:55, #12 - 21:25, #13 - 23:00, #14 - 24:25, #15 - 25:55, #16 - 26:25, #17 - 28:30

Drupal.org

#18 - 29:55, #19 - 31:20, #20 - 32:00, #21 - 33:20, #22 - 35:10, #23 - 35:50, #24 - 36:30

Theming - 37:45
#25 - 38:05, #26 - 39:35, #27 - 40:25, #28 - 41:00, #29 - 42:15, #30 - 44:30, #31 - 45:25

Views
#32 - 46:30, #33 - 48:10, #34 - 50:10, #35 - 52:00, #36 - 54:20, #37 - 54:45, #37.5 - 56:16

Javascript
#38 - 58:00, #39 - 59:15,

Drupal Development and Coding - 59:40
#40 - 60:05, #41 - 62:45, #42 - 65:10, #43 - 67:35, #44 - 68:20, #45 - 70:10, #46 - 71:40, #47 - 73:00, #48 - 74:20, #49 - 75:15, #50 - 76:00

Reply

BCSWebstudio

sweet

thanks for the index! brilliant.

Reply

Amnon Levav

Tips #4/Tip #28 Alternatives, Tips#30 use.

Regarding your focused drupal search suggestion (tip#4), we can also create a google CSE. Here is my Drupal CSE - done for Drupal Israel. It's much better then a simple google search and yet it's not limited to Drupal.org.

Regarding tip #28 - (41:00) - Another great way to beautifully print vars is to use the devel module's dprint_r function. One advantage is that it puts everthing in a scrollable DIV, so your theme is kept whole.

#30 (44:30) is a cool trick! format_interval seems like a great place to look on how to change the way dates are formattted for foriegn languages - a lot of customization is needed there. Sometimes, the order of date interval strings in foreign languages is completely different then on English - this post remedies that.

Reply

ghowell

drupal

pretty cool tips, i just downloaded the 6.2 version and set up a blog on my site. it's awesome. blog

Reply

Thomas

Thanks

Thanks a lot for your great list.
It ist absolut helpful for a newbie like me.
Great!

Greetings from Europe.

Reply

Sarah Summer

You have compiled a really

You have compiled a really good resource list.And that must have taken a lot of your valuable time! I thank you for the list and your effort.Do keep building similar lists as this one.
Thanks

Reply