Using hook_init() to include CSS and JS files

For some time, I've been using the most hackish ways of including custom CSS and Javascript in my site via themes and custom modules. The problem has been (at least, in Drupal 6) that the hook_preprocess_page() function, inside which I'd really like to include my drupal_add_css() and drupal_add_js() functions, due to the fact that it's easy to see what page I'm on, or what kind of page I'm on, is not able to add CSS or JS to the page, due to the order in which the hooks are fired.

I've often just put my JS and CSS includes (via the drupal hooks) into the end of my custom module file, instead of inside a function at all.

However, a much cleaner way to include your CSS and JS is inside your own implementation of hook_init(). For example:

Adding Module Stylesheets using drupal_add_css()

A couple days ago, when building a quick site with limited functionality (basically a pretty front end to a database website), I ran into a hiccup with my custom module/theme for the site, which caused me to scratch my head for a few minutes.

In my custom module (called 'idcards'), I added a stylesheet for a couple forms on the site using the drupal_add_css() function:

 * Implementation of drupal_add_css()
drupal_add_css(drupal_get_path('module', 'idcards') .'/idcards.css');

Later on in the development, I added a custom theme (based off a Zen subtheme I use for many smaller sites), and in that custom theme's .info file, I added a stylesheet named idcards.css.

When I cleared all the caches, I noticed the custom form styling (added by the module's idcards.css file) was missing, and on further investigation, I found that the module's idcards.css file was not being added to the pages!

Full Site Buildout: Part 1 - Putting the Puzzle Together

Part 1 of a series: Building out a full Drupal site in a weekend.

Before you start building your website, you need to get all the parts of the site together, and have a good plan for what you'll need and how you'll do it. For many organizations, this can be a huge hassle, as you'll have to go through planning meetings, make diagrams, have all kinds of changes, and end up pre-stressed... and that's before you start working on putting the site together!

Luckily, for this website, the requirements are pretty simple: I can do whatever I want. But I can't get started from that point, so I put a few requirements down on paper, then grabbed everything I needed.

Building Out a Full Drupal Site on a Busy Weekend

This weekend I am going to attend the Catholic New Media Celebration. I'll be on two plane flights, I'll be sitting at an airport for a few hours before each flight, and I'll be at a convention all day Saturday. I'm hoping to build out a new site idea I've had lurking in the back of my head for some time: Open Source Catholic.

List of Downloaded Files for Drupal Install

In the past 45 minutes, I've been jumping around downloading all the different modules and tutorials I think I'll need. I've also saved some of my previous work on other Drupal sites in case I need to refer to a code snippet along the way while I don't have Internet access. I'm going to call it a night for now (I need to pack!), but tomorrow, beginning at the airport, I'm going to start working on the site.

Using Boost with Drupal - Making a McWebsite

Boost Module for Drupal - Make Your Site a McSiteTo the uninitiated, Boost is a module for Drupal which has the potential to make your Drupal-based website run many times faster than it's currently running. Boost basically converts pages on a Drupal site into static html files, and allows your website to direct anonymous (non-logged-in) users to the cached html pages.

Doing so speeds your site up quite a bit, because instead of your web server having to run some PHP scripts and connect to your website's database, the server can simply send the complete html file, which requires no extra processor cycles or memory to compile. If your website has a lot of anonymous traffic, the potential speedup is very large. Instead of serving hundreds of users per minute, you could serve thousands.

Case Study: Saint Louis Review News Website

In what will be the first of, I hope, many case studies, I review the process of redesigning the Saint Louis Review website, from the ground up.

The Saint Louis Review is a local Catholic diocesan newspaper serving the nearly 500,000 member Archdiocese of Saint Louis. The newspaper has had a website since the late 90s, which was ported to a custom-designed CMS in 2001. The PHP/MySQL-based site ran quite well throughout the first decade of this millennium, but was in need of either a serious overhaul or a redesign, to go along with the paper's new tabloid layout in April 2009.

Old and New Saint Louis Review Websites

The decision was made in 2007 to port the website to Joomla, but after a few months, a new editor, and more work, it was determined that, due to its extensibility, flexible out-of-the-box permissions, and standards/SEO-compliant codebase, Drupal would be a better fit for the site. Work was begun in January of 2009 to transfer the custom CMS' articles database (over 17,000 articles) to a Drupal site, create a new template based off the colors and design of the new tabloid-format paper, and integrate an easier-to-manage ad system and back-end.

Global Redirect: A Drupal Module that Gets it Right

Global RedirectThere are only two or three Drupal modules that I have installed on every single Drupal site I set up. At the top of this short list is Global Redirect. There are many reasons for its existence, not the least of which is Search Engine Optimization. Global Redirect does such niceties as remove slashes from the end of URLs and makes sure the home page of the site is the standard home page, and not an alias to it (like /front, or /home-page).