Tag Archives: Drupal

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

Drupal – Synchronize Translation

We can translate contents/nodes by activating the Content Translation.
Drupal – Content Translation
 

The translated node itself has not relation with the original node except their node ids are mapped. So I can have a price $10 in the English item but $1000 in the Traditional Chinese item. It will be quite difficult to manage when the amount of content is getting more and more. Therefore, i18n provides another feature called Synchronize Translations. Whenever a node is updated, the synchronized fields of all other corresponding nodes are also updated. Continue reading Drupal – Synchronize Translation