Drupal Base Themes

1 Comment

Using a base theme when it comes to creating a theme for your Drupal site can be a polarizing issue. On the one hand, some people swear by using Garland as a starting point, customizing it until it looks nothing like the original theme at all. However, I personally prefer the other approach – start with a stripped back base theme and build from there.

There are numerous benefits for using a base theme to build your new Drupal theme. Depending on which base theme you go with, some of the benefits include:

  • -Sensible CSS resets, so your HTML elements are consistent across browsers and platforms
  • -Included templates, meaning you get a great set of templates for your page, node, blocks etc to work with and build off.
  • -Most base themes will include additional classes, making your CSS more concise and easier to write.
  • -Additional functionality, such as block configuration links and module integration.
  • -Out of the box compliant XHTML and CSS.

While there are numerous benefits to using a base theme, there are many people who will offer counter-arguments. These may include:

Quicktabbing with Quicktabs

0 Comments

Quicktabs has quickly become one of my favorite Drupal modules of all time. To think that I was actually wasting time creating tabs by using jQuery plugins, and writing custom AJAX. Creating tabbed content is one of the most popular techniques used on the web today, and with Quicktabs it has never been easier to add tabs to your Drupal site - even with AJAX!

First you'll want to install Quicktabs

Once you have Quicktabs installed, there are a couple of ways to generate tabs. You can do it through the Drupal interface, or you can do it programmatically, but first, make sure you have some content that you want to show in tabs! Quicktabs works with your existing content. You can tab between views, blocks, nodes, or a mixture of these.

For this demo, we'll use Views and set up 2 displays filtered by a certain taxonomy term. We will then create a tab that displays nodes of each taxonomy term respectively. Make sure you have some taxonomy terms to choose from for each post. Then you'll want to create a view called "my_listing", or whatever makes sense for you.

Keeping your Drupal theme organized.

6 Comments

When working with large websites and web-applications the number of files on your theme folder can grow quickly, and if you're not organized it can get very messy . As a result you’ll find yourself spending a lot more time looking for bits of code every time you have to change or update something.

Here are some tips to help keep you organized.

File Structure:

On Drupal a couple of files have to be on your theme rood folder:

  • - page.tpl.php
  • - node.tpl.php
  • - template.php
  • - themename.info
  • - comment.tpl.php

If your file doesn't have to be on the theme root folder, it should be organized with similar files on subfolders. Here is what we typically use:

Using different “page.tpl” on Drupal 6.

9 Comments

Often we are in a situation where we need one, or several pages of a website to have a completely different structure. When this happens you will most likely have to use a different page.tpl .

The simplest way to change your page.tpl is to use the website's URL to explain to Drupal what page.tpl it should be using. For example, to assign a different page.tpl to a page that is under “yourbasepath.com/splashpage” all you have to do is follow this one step process. Go into your theme folder, and create “page-splashpage.tpl.php”. Once Drupal recognizes the link (/splashpage), it will then know to use this specific .tpl file.

But what happens when you need to use the same template more then once? This is when a page preprocess will come in hand! Here is what we’re going to do:

On your template.php we’re going to preprocess the page. It looks something like this:

Theming Views on Drupal 6 (the simple way)

5 Comments

There are several ways you can theme a view on Drupal, and this tutorial will describe a simple and quick way to accomplish just that. I assume that you’re familiar to working with Views and CCK, so I won’t go in much detail on the process of creating the view and content type.

For this example I’m creating a block simple view that will display a teaser for the 3 latest blog posts.

First thing we’ll have to do is create the actual template file on the themes folder (I’d recommend that you create a folder for all the views, but this is optional). We’ll start by going to the views interface to find out how that file should be named.

On the Views interface select “Theme: information” under “Basic Settings”.

You’ll see a list of the possible files you can use listed from the most general(full page)on top to the most specific on the bottom. We’re going to be selecting one option on the “Row Output”. If you don’t need to be too specific about theming that view, you can use the second option. Copy the file name and create that file on your themes folder.

Back to the view interface again. Select “rescan template files” and the file you created should be highlighted on the interface.

Here is where the real theming begins. We’re going to create the variables we need on the template file. In this case, I’ll be creating $title and $body variables.

Go to your views interface under “fields.” However, the links to the fields you want to use are found at the status bar, on the bottom of the browser. We’re looking for the information on the last section of the link. For the Title field, my link looks like this: http://domainname.com/admin/build/views/nojs/config-item/footer_blog/block_1/field/title so the information we’re looking for is “title”.

Knowing that you can set up or title variable like this: $title = $fields['title']->content; And repeating the process for the body will get you something like this: $body = $fields['body']->content;

Now that you have your variables set, can go ahead and theme your file at will! You’ll find yourself dealing with a very simple and clean template file!

Do you have a different technique to theme your views? Share with us!

How to create a video carousel: Feed API + Emfield + Views Carousel

3 Comments
How to create a video carousel: Feed API + Emfield + Views Carousel

Recently, I had to create a carousel with YouTube videos (thumbnails). I downloaded and enabled 'emfield', 'emthumb', 'emvideo', 'viewscarousel' and 'jcarousel' modules. I created a new content type - youtube_video - with a field field_youtube_video of "Embedded Video" type.

Now I had to create a view. In a new view's Basic Settings, I set Style to Views Carousel and added Fields -" Content: Youtube Image Thumbnail (linked to node)" and "Node: Title". I also set Filters to "Node: Type = Youtube Video".

You will also want to modify some settings to make it look as you like, but this is pretty much everything that you need to create a carousel - just add some nodes and enter the URLs to a YouTube pages of video you want to display.

But I needed more than that - I needed YouYube_video nodes to be created for me from this RSS: http://gdata.youtube.com/feeds/base/users/alfresco101/uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile

Validating files on nodes with FileField and CCK

1 Comment

Recently I was working on a project where users were able to upload videos, the format in our case didn't matter since we were uploading to Youtube anyway. Allowing users to upload videos was easily done with the Video Upload module and the CCK module. This module allowed us to upload videos directly to our Youtube account. From here, we waited for the next cron run and the video's would be processed, published and viewable by users of the site. Fast, simple, and all done without any custom coding, sweet!

Creating nodes programmatically that have CCK image fields in Drupal 6

9 Comments

When creating nodes programmatically it's easy enough to give the node a
title, body, and type by using the following:


$node = new stdClass();
$node->title = 'title';
$node->body = 'body text';
$node->type = 'type';

These are simple properties that ALL nodes will have. What about nodes with CCK fields attached to them? Well for text fields we can simply use the following:


$node = new stdClass();
$node->title = 'title';
$node->body = 'body text';
$node->type = 'type';
$node->$field_name[0]['value'] = 'TEXT'

Where $field_name can take place of the internal CCK field name (field_XXX_XXX)

That covers the text fields but what about images? Here's a little background on the situation that was put infront of me. I had images on a different server which I needed to attach to an image field on one of our content types. So I used a combination of cURL and a CCK function in order to attach the images to the nodes.

Classy Captions with jQuery and FCKEditor

2 Comments

Let's say you have a news article content type and you use FCKEditor so your non-html savvy publisher can post a story with some basic formatting. One thing they will have difficulty doing is creating a caption for any images they insert into the body. This is not to say that they couldn't just bold some text below the photo and call that the caption, but this just isn't ideal. There is no relationship between the caption and image this way.

You could just switch off FCKEditor and stick a p tag with a class below the image, but if you've ever used FCKEditor you know how ugly and unmanageable this can be. And, still there is no real 'relationship' between these two.

Here's an elegant solution. How about re-purposing the img's "alt" attribute? After all, the "alt" attribute on an image is supposed to describe what the image is. There is no character limit, and these can make great captions. Here's how you can easily set up captions in your news articles.

First you'll want to create a class called ".caption". You can style it however you want, just be sure that it doesn't have any top margin so it stays flush to the image.

The Drupal Quiz Module

8 Comments

My first experience with the Quiz module was amusing, to say the least. A project, which I had just finished, required registered users to be able to take different quizzes and successfully complete them in order to receive a certificate. I turned to the quiz module to avoid any custom coding. Overall, I was able to do what I needed. However, below I have listed three issues I had ran into:

1. No import/export of quizzes.

  • 1 of 2
  • >