Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Keep your code out of the database when developing in Drupal

Parent Feed: 

As I’ve mentioned before, version control with Drupal is tricky because a lot of configuration changes are stored in the database. Version control is vital because you should be maintaining multiple workspaces so you do not work on production. The last thing you want to do, then, is to make this worse by putting PHP in your nodes and blocks.

2bits wrote up a great post explaining that you should free your content of PHP. Yes! Read that! Follow it and add it to your Drupal bible.

2bits goes on to explain how to pull PHP enabled nodes and blocks into modules, and points out that we’ve been able to export a view into a module all along.

In addition, I should note, that you should also avoid using the contemplate module because it stores all of your theming for your content types in the database. I know I know, some of you absolutely adore it because it makes theming easier. But you should instead learn to put the code you’re adding to contemplate inside template files, which can then be under version control.

The main benefits of contemplate is the exposure of available variables to each content type, and with a click that variable can be added to the template. It makes it easy, then, to display your content just the way you want. It also exposes some PHP scripting to ensure that all content gets displayed (like all terms, or all entries in a multiple values enabled field), which is helpful for those just starting out and are still novices with PHP. Not everyone understands objects, arrays and loops. (All the programmers are likely choking at this comment, but Drupal is accessible enough where scripting is not a requirement in order to build a site.)

For a long time, I would enable contemplate solely so I can browse through the available variables it exposes. However, I now primarily use print_r($node) instead as a tool to see what is available. The Devel module provides all sorts of utilities while developing, including the ability to see all available variables within a given node in a fashion that is nicer than print_r().

Since contemplate’s greatest appeal is to beginner Drupal developers, it would be nice if extra features could be added to help teach how to make a theme, or be a tool to assist in making a theme easier. Suppose if contemplate had an optional feature to preview and then export the desired template into template files in much the same fashion as the template wizard for Views behaves. Such a feature could help bridge the gap and demonstrate how themes work.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web