Follow us on Twitter!
Syndicate content
Login - Register - Latests submissions

conventions

There are some conventions when using contributed modules and/or themes. Most users would want to place them in modules and themes folders.

Don't ever do that! Never place modules or themes in these directories!

Everything added to a fresh Drupal install should go somewhere in the sites directory:

  • Contributed modules (from drupal.org) should go in sites/all/modules/contrib
  • Project custom modules should go in sites/all/modules/custom
  • Contributed themes (from drupal.org) should go in sites/all/themes/contrib
  • Project custom themes should go in sites/all/themes/custom

Note that if you have a multisite environment, you could place somes of the modules/themes:

  • in sites/default/..
  • or sites/example.com/..
  • or sites/anotherdomain.com/..
  • and so on..

... depending on your configuration.

Note that using a contrib and custom directory convention will help you find out which modules are contributed by the drupal community and which you have developped specifically for the website.

This will allow you to update more easily your websites as the only directory you will need to preserve will be sites/*.

Use full PHP tags

Write:

<?php print $foo; ?>

Don't write:

<? print $foo; ?>

Semicolons
Write:

<?php print $foo; ?>

Don't write:

<?php print $foo ?>

No closing tags
When writing a module or customizing your theme template.php, don't use PHP closing tag ?>.

Notice that at the bottom of the following snippet, there is no PHP closing:

<?php
// Your file starts here
function phptemplate_foo() {
  return $bar;
}
// Your file ends here
// Don't add PHP closing tag

By doing this you prevent PHP interpreter to stop and restart on the next source code file. This mean better performance.