Category Archives: CMS

Drupal – Add Javascript in Theme

As discussed before, we can add Javascript/JQuery in Drupal modules.
Drupal – Create Javascript for Module

So if the Javascript/JQuery is related to the layout and independent of the module, we should add it in the theme instead. For example, i want to have a alert box whenever a page is loaded, i should then add it to my current Drupal theme. The steps are listed below.

1. Open you current theme folder and add the following line in the theme.info.

  • scripts[] = js/theme.js

Continue reading Drupal – Add Javascript in Theme

Drupal – Add Javascript in Module

In Drupal, you can add your Javascript to module or theme. If the javascript is related to the module logic and independent of the theme, we should add the .js file in the module. Moreover, Drupal already includes the JQuery library. So we can use the JQuery functions in the .js file.

Let’s recall the custom module we have created in previously.
Drupal – Create a Block

i want to show an Javascript alert box whenever the block is shown. Let’s create a custom.js in <drupal_root>/sites/all/custom.

jQuery(document).ready(function() {
	alert("Hello World");
});

Continue reading Drupal – Add Javascript in Module

Drupal – Using JQuery UI

You can make some JQuery UI function with the help of the JQuery UI module. For example, the Date module of CCK allows the Date Popup feature which required JQuery UI. The current support version for JQuery UI is 1.6.

1. Let’s download the Date and JQuery UI modules and extract them into sites/all/modules. We also need to download JQuery UI 1.6 library to sites/all/modules/jquery_ui. Continue reading Drupal – Using JQuery UI

Drupal – Customize the Views Query

I want to create a taxonomy view which shows the term name and the term image. For those terms without term image, i want to filter out them. Unfortunately there is no term image filter in the view setting. One work around is overriding the view query by implementing the hook_views_pre_execute(&$view) in a custom module. Before you construct the new SQL, you should set all your desire settings in the view editing page first. Then you can create a new SQL base on that view query.

So in the custom module, add the following function. Continue reading Drupal – Customize the Views Query

Drupal – Automated URL Alias Using Pathauto

All Drupal contents are base on node. Whatever contents you create, it has a url http://<drupal_root>/node/<node_id&gt;. For each content, you can customized the URL alias but think about if you have 100 nodes, you will not enjoy setting the each alias manually. It’s better to pass the job to PathAuto.

After installation, go to @ Administer –> Site building –> URL aliases. There is a new tab called Automated alias settings. For every Story content type, i want the URL alias to be http://<drupal_root>/stories/<story_title&gt; so i set stories/[title-raw] in Pattern for all Story paths. Continue reading Drupal – Automated URL Alias Using Pathauto

Drupal – Ubercart Localization

Localization with Ubercart is somehow a bit difficult. Assume we have 2 languages, English and Traditional Chinese, installed. For a particular product, there will be one node representing the English one and the other node representing the Traditional Chinese one. If you add the English node into the cart, it will not be translated in the cart and checkout page. In other words, they are treated as 2 different products.

The following example can localize the Product content type even in the cart and checkout page. and it is based on the work by Stewart Adam. Please refer to for the post – Translating or internationalizing an Ubercart store: Common problems & solutions more information.

1. Create a custom module and add the following hook implementation in the .module file. Continue reading Drupal – Ubercart Localization

Drupal – Build an Online Store with Ubercart

The Ubercart module is a complete E-Commerce suite which turn your Drupal website into an online store. It is a very big module which contains a lot of features. In this article, i will try to show you those basics but actually i am not intimate with it very well.

Before you start, it is recommended that Imagecache, CCK Image field and Views are installed. This allows our store product image showing to the customers.

1. Download and install the Ubercart – core features. Continue reading Drupal – Build an Online Store with Ubercart