How to add Drupal data to Javascript using drupal_add_js

There are times when one will need to pass Drupal data in Javascript or JQuery. One example that comes to mind is for analytics purposes, say after a user clicks on a specific link, you’d want to find the node type of the page the user made this click.

In your .tpl.php, template.php file or anything similar that deals with your theme, you can add the following (Drupal 6 installation):

drupal_add_js(array('myvar' => $node->type.'|sometextifneeded'), 'setting');

Then, in your JavaScript file, using JQuery, you can add the following within a specified namespace (remember to reference your jquery file):

Drupal.behaviors.mynamespace = function () {
$("#nav li.about").bind("click", function() {
var100 = Drupal.settings.myvar;
alert(var100);
});
}

Please comment if you have questions!

Share

Budweiser poster shows opening day for MLB up at NYSE

I’m really not a fan of baseball – but to kickoff the 2011 MLB season, I thought this would be cool to share. The banner says ‘Grab some Buds,’ makes me wonder if they are giving out Buds in front of the New York Stock Exchange.

Budweiser banner for MLB at NYSE

Budweiser banner for MLB at NYSE

Wonder if their horse drinks Buds?

Budweiser horse

Budweiser horse

If they are giving out Buds (which I doubt), do let me know so I can grab one to go!

Share

Tyra Banks brings fashion and beauty to NYSE

For all you Tyra Banks fans out there, you may have missed out on the big poster display over at New York Stock Exchange today.  She apparently started her own website called TypeF.com and if you are all about fashion and beauty, feel free to check it out.  If you ask me, I think she look marvelous in the poster!  Here’s a view if you missed it.

Tyra Banks promoting her Fashion and Beauty website

Tyra Banks promoting her Fashion and Beauty website

Share

Samichlaus Classic is the best tasting beer ever

I received a 12-oz bottle of Samichlaus Classic as a gift (as well as other various beers) and this happened to be one of the best beer gifts ever – the taste is super sweet, super smooth, and super strong!!  Believe or not it’s 14% alcohol by volume, yes for one bottle – beats your typical Coors Light by a 3:1 ratio.  Drink two and nap-time will be calling your name.  It’s a product of Austria – boy do these guys know good beer.  If you’ve ever tried Dragon Stout (Jamaican), it’s quite similar but I think Samichlaus Classic takes it by a short margin.

Samichlaus is the best

Samichlaus Classic packs 14% alcohol

Samichlaus Classic

Samichlaus Classic packs 14% alcohol again

Share

Pepsi celebrating Super Bowl 45 by NYSE

If you are by New York Stock Exchange (NYSE), check out what they’ve got – something related to Pepsi and the Super Bowl.

Pepsi celebrates Super Bowl at NYSE

Pepsi celebrates Super Bowl at NYSE

Share

More Articles

Baron’s Blazing Hot Pepper Sauce is highly recommended

A tool to automate your tests for web applications

Remote Desktop Connect as an Internet TV app