Knowledge Base > Syndication Services > Editor's Desk and Widgets
Search the Knowledge Base
 
Date Modified
Friday, June 27, 2008
Using the ${BuzzId} token in the JavaScript template to uniquely name functions

In the template HTML of a widget, the unique BuzzId of your widget has always been accessible by using the ${BuzzId} token. Only recently has the BuzzId now become available in the JavaScript.


The BuzzId is a helpful token in that it can be used to uniquely name CSS classes, object Ids, and function names. By uniquely identifying widget objects, you can ensure that your widget will load properly, without CSS collisions or JavaScript function name confusion.


In the JavaScript, if you have a function defined like so:

function getText_${BuzzId}(name){
    alert("hello " + name);
}


In the template HTML you would call it like this:

onclick="window['getText_' + ${BuzzId}]('world')";



Or if it is a function you'd like to run after the widget renders (like calling the LoadTabs function), you can place it in a post render callback:

${% AddPostRenderCallback(function(){ window['getText_' + BuzzId]('world'); }) %}



Knowledge Base Software - myKB.com