Theme UDFs
UDF ( User Defined Functions ) are a great way to add more power to your theme, and your theme settings.
Below are some common UDFs you might want to use in your themes, or templates on how you could create some of your own.

Example UDFs

LoadHelpFile()

This is a useful method for standardizing loads HTML for the fieldHelp Modal. The fieldHelp setting using this function would look like this
loadHelpFile( 'cbBootswatchTheme.html' );
Since the helpFilePath is not passed in this example, it defaults to the Theme's includes/help/ folder.
Note: One concern when using this is relative pathing of assets, since the modal is generated in one folder, and the includes are in another folder.
1
/**
2
* loadHelpFile - helper function for loading html help into a variable for modal
3
* @helpFileName - the name of the file to read and return
4
* @helpFilePath - the relative directory for the help files. Defaulting to ./includes/help/ inside the theme.
5
* @return the contents of the file or empty string if the file does not exist
6
*/
7
function loadHelpFile( required string helpFileName, string helpFilePath='./includes/help/' ){
8
try {
9
return fileRead( arguments.helpFilePath & arguments.helpFileName );
10
} catch( any e ){
11
return '';
12
}
13
}
Copied!

selectMediaManagerFolder()

This function gives you an array of Media Manager folders, so you could use in a optionsUDF setting, to allow the Theme Settings form to display a dropdown box with a list of folders. This would be great for a slide show, where the users select the folder, and all of the contents of the folder could be shown in the slideshow.
1
function selectMediaManagerFolder(){
2
var event = getRequestContext();
3
var cbSettings = event.getValue(name="cbSettings",private=true);
4
var defaultDir = expandPath( cbSettings.cb_media_directoryRoot );
5
var allDirectories = directoryList( path=defaultDir, recurse=true, listInfo="query" );
6
var result = [];
7
for( var directory in allDirectories ){
8
if ( directory.type is 'dir' ){
9
var theString = replaceNoCase( directory.directory, defaultDir, "", "all" ) & '/' & directory.name;
10
theString = replaceNoCase( theString, "\", "/", "all");
11
theString = replaceNoCase( theString, "//", "/", "all");
12
result = result.append( theString );
13
}
14
}
15
return result;
16
}
Copied!

getBootstrapStyles()

Bootstrap has a set of pre-defined styles, used in alerts, buttons, and many other styles you can use in your website. Having a UDF like this, allows you to create a setting that the User can select the button style type.
1
array function getBootstrapStyles(){
2
return [
3
"default",
4
"primary",
5
"success",
6
"info",
7
"warning",
8
"danger"
9
];
10
}
Copied!

getBootstrapSwatches()

We use BootSwatch in several Themes, because it gives the user of the theme a lot of complete styles, in one theme. This UDF shows you how you can return a list as an array, so a user could select the BootSwatch they would like to use.
1
/**
2
* Build the swatches options
3
*/
4
array function getBootSwatches(){
5
return listToArray( "cerulean,cosmo,cyborg,darkly,flatly,green,journal,lumen,paper,readable,sandstone,simplex,slate,spacelab,superhero,united,yeti" );
6
}
Copied!
Last modified 3yr ago