Using jQuery in the Cms

Release 1.1 - ...

You can use the powerful jQuery libraries in the Smartsite CMS as well.

As you may now, the registry setting \<site_name>\manager\includes can be used to include global javascript libraries.

Simply adding a reference to jQuery.js isn't enough though. Since Smartsite CMS uses the $ variable for other purposes, you'll have to use the jQuery noConflict() method.

There are a number of ways to do this. The default jQuery variable in Scf is $j, so it might be a good thing to add jQuery.js, then add jQuery.scf.js:

  CopyCode image Copy Code
/scf/jquery/jquery.debug.js;/scf/jquery/jquery.scf.debug.js

There is still one thing to be solved here: the Scf framework must be started, using $j.scf.start(). This method call is not automatically attached to the jQuery DomLoaded event ($j(document).ready()), because Scf can be started in two ways in iXperion (using the StartupMode property).

In the Cms, you'll have to kickstart Scf yourself, since there's no Scf macro doing it for you...

Create a Javascript file in /scf/jquery/, named jQuery.Cms.js:

Javascript CopyCode image Copy Code
$j(function(){$j.scf.start({})});

Note: from 1.2 onwards, use:

Javascript CopyCode image Copy Code
$j(function(){$j.scf.start({conflict: true})});

 

Now, modify the registry entry 'includes' as follows:

  CopyCode image Copy Code
/scf/jquery/jquery.debug.js;/scf/jquery/jquery.scf.debug.js;/scf/jquery/jquery.cms.js

Done. You are now ready to use any jQuery script and plugin, as long as it complies to using the 'jQuery' variable itself (not '$'), or uses the wrapping trick:

Javascript CopyCode image Copy Code
(function($) { /* some code that uses $ */ })(jQuery)