Today I Learned...

Creating Custom Formatters with Display Suite

Here at EchoDitto, we've been making heavy use of the Display Suite module. It obliterates a lot of the more tedious theming issues we typically run into when building out a Drupal site, and for the most part, we love it. But as with any solution that takes logic out of code and puts it into the UI, if you want to do anything that isn't already provided by DS, you're going to have a write a bunch of code.

So far, the biggest drawback to using DS that we've experienced so far is the lack of formatters.

Never touch your local /etc/hosts file in OS X again

In each of my posts on setting up a local development environment on OS X, it's mentioned that you need to add your website's domain, even though it's local, in your /etc/hosts file. My preferred way to edit the hosts file on OS X is using Gas Mask. If you wanted to create the local virtual host projectx.dev, you would add the line 127.0.0.1 projectx.dev in /etc/hosts or with Gas Mask, and then use that same value in either ServerName in Apache or server_name in Nginx. This can be tedious for adding new sites. Luckily there's a way to set this up once and then never have to edit your hosts file again for adding new local virtual hosts.

Redirect all port 80 requests to port 8080

Alan Ivey's picture

In my previous post, I walked through how to set up a local environment using Nginx running on port 8080 so as to avoid running anything as root or with sudo. Something that I've found incredibly annoying is when I forget to specify the port I get an error in my browser, or Chrome might even suggest something based on a search term. It's fairly easy though to configure Apache to route everything to another port.

Video Thumbnails with Media and YouTube or Vimeo in Drupal 7

Paul Venuti's picture

Today, one of the designers I work with asked me a pretty simple question about a Views-based list of videos. The listing displays thumbnails of videos being pulled from YouTube and Viemo. The question was: how do I change the size of the thumbnails?

It's easy enough to change the size of images, but the process gets fairly confusing when it comes to other content types. Here's a quick breakdown of the steps I took to enable video thumbnail resizing:

  1. Create an image style.
  2. Set the effect you want on the image style.
  3. Create a file style.

EJS Views Helpers With Backbone-Rails

Tyler Renelle's picture

Backbone-Rails is a useful gem for setting up Backbone.js in your Rails 3.1 app by providing all the necessary javascript files & dependencies (easy future upgrades with bundler), as well as some generators to setup your MVC directory structure. It uses EJS (Embedded JavaScript, part of Underscore.js I believe) as it's default javascript templating language and installs the ruby-ejs gem as a dependency.

Node.js and NPM on CentOS

Alan Ivey's picture

The preferred way to install node and NPM seems to be installing from source, but I'm a perennial fan of using packages to keep things tidy, especially if I need to uninstall something. I started by going to the Node.js download page, and through to Installing with a package manager. I installed the yum release RPM for the tchol.org repository as directed and installed nodejs and npm with yum. From there, I ran into two problems but thankfully they were fairly easy to resolve.

Removing Behaviors Using a GMap Macro

Paul Venuti's picture

I'm building some maps for a client using the GMap module and came across the following simple problem: using a GMap macro, how do you remove a default attribute?

The GMap module lets you set a number of default attributes for your maps: width, height, center position, initial zoom, and so on. If you want to change any of the default settings for a given map, you need to specify your overrides in a GMap macro, which looks something like this:

[gmap zoom=3| width=500px |height=350px]

It's all simple enough until you get to the behaviors.

Preventing empty CCK-based blocks from printing

Paul Venuti's picture

Today I learned that if you have a Views-powered block that uses CCK fields; and the CCK fields are empty for all the returned rows; then Views doesn't realize you've got an empty set and it still prints all the scaffolding for your block – the admin links, the container divs, and so on. The content of the block is empty, but the HTML still takes up space and throws off your layout.

Fixing this is easy. To prevent an empty CCK field-based Views-powered block from being output, add a filter on the CCK field and set the filter to Is not empty (NOT NULL).

Keep Drush Up to Date

Alan Ivey's picture

We're big fans of Drush. It's installed on all of our servers and it's a great way to perform maintenance tasks, download core and modules, and much much more. I'm not a big fan of installing from zip files though, so let's use git to easily keep our Drush install up to date.

Set Sitewide Default Context in Drupal

In Context 3 they removed the sitewide default context, that is, the context that can be set to be enabled when no other context is active. The sitewide context, which is enabled at all times, is still available.

But, in its place, Dev Seed has added a very powerful feature, sneakily powerful, in fact.

You can set a context to be active using another context. Seeming kind of meh? Well, read on. You will soon see, young apprentice, just as I did just earlier today.

First, name all the contexts you DON'T want this context to coincide with in a regularized way, like

Delicious Feed Broken? Delicious Changed Its Domain Name

Dan's picture

I ran into an issue recently where Delicous links weren't being updated as expected. It turned out sometime in August 2010 Delicious switched from using http://delicious.com/ to http://www.delicious.com/

I fixed my problem by changing the Views filter from http://delicious.com to http://www.delicious.com

Most changes should be as easy as that.

Updating your Drupal site using Drush

Madeleine's picture

A few weeks ago, Alan wrote about how to find out if your Drupal and Wordpress sites are up to date. So, what if you find out your Drupal site is horribly out of date - core, modules and all? What then?

If you run the script Alan wrote about, or you simply notice the alert in the admin section of your site notifying you that your site has updates available, most of the time you'll want to implement at least some of these updates.

Making Drupal Happy: When Themes and Modules use the same name

Madeleine's picture

We came across an issue with a site recently, where the name of the custom module file was the same as the name of the theme. So, for example, if the theme name was Bork, the module name was bork.module. This can cause a variety of problems since the two share name space. Problems can include blocks disappearing (both from your site, and from the /admin/build/blocks menu), printing $content returns only 'array,' and more.

Custom CKeditor Classes in Style Dropdown

Jeremy John's picture

While looking up how to add custom styles to CKeditor's dropdown, I came across a helpful yet tiny custom module from my friend rootwork.

Turn it on and hack on it to add new styles. You can't add styles to the 'a' tag, FYI, create a style for a span tag instead.

Customizing ShareThis WordPress plugin

Madeleine's picture
I wrote about this on my personal blog after realizing that having the ShareThis links at the end of my blog posts might actually prevent them from being shared as much, assuming that most people won't read the posts in their entirety (sad, but probably true). For those of you already confused, ShareThis is a WordPress plugin that enables users to share your content.