LogoLogo
SourceSupportTraining
v4.x
v4.x
  • Introduction
  • Intro
    • Introduction
      • What's New With 4.2.0
      • What's New With 4.1.0
      • What's New With 4.0.0
      • Upgrading From v3.x
      • About This Book
      • Author
  • Getting Started
    • Installation
      • System Requirements
      • CommandBox Installation
      • Source Installation
      • WAR Installation
      • Express Installation
      • Existing ColdBox Application
      • Upgrading ContentBox
      • Docker
    • Quick Guide
  • Usage
    • Using ContentBox
      • Content
        • Publish Content
          • Blog
          • Sitemap
          • Content Editing Tips
            • Editor Features
            • Dynamic Variable Output
            • Markdown Support
            • Scheduled Content
        • Consume Content
          • Content Store
          • Categories
          • Media Manager
          • Menu Manager
      • Comments
        • Inbox
        • Settings
      • Look & Feel
        • Active Theme
        • Global HTML
        • Themes
        • Widgets
          • Inserting a Simple Widget
      • Modules
        • Installing Modules
        • Managing Modules
      • Users
        • Manage
        • Permissions
        • Roles
      • Tools
        • Import
        • Export
        • Static Site Generation
      • System
        • Auth Logs
        • Geek Settings
        • Settings
          • Site Options
          • Admin Options
          • Security Options
          • Login Options
          • Content Options
          • Editor Options
          • Media Manager Options
          • Gravatars
          • Notifications
          • Mail Server
          • Search Options
          • Login Options
        • Security Rules
        • Updates
  • Developing
    • Developing For ContentBox
      • Front-End Development
        • File Structure
        • Theme Development
          • Theme Settings
          • Theme UDFs
          • Theme Templates
          • Theme Layouts
          • Theme Views
          • Theme SEO Functionality
        • The Content Store
        • Customizing Views
        • Customizing Layouts
        • Managing Assets
        • Customizing Navigation
        • Global Variables
        • Template Variables
      • Back-End Development
        • Overriding ContentBox Settings
        • Modules
          • Installing a Module
          • Using a Module
          • Module Locations and Conventions
          • Build a Module
          • Scaffold a Module
          • Theme your Module
          • Build an Admin Module
          • Adding Admin Menus to your Module
          • Adding Meta to your Modules
        • Widgets
          • Core Widgets
          • Simple Widget
          • Widgets with Arguments
          • Multiple Render Function Widgets
        • JS and CSS Assets
        • Interceptors
        • Accessing Logged in User
        • Customizing the Admin
        • Staying on the Upgrade Path
Powered by GitBook
On this page
  • Example UDFs
  • LoadHelpFile()
  • selectMediaManagerFolder()
  • getBootstrapStyles()
  • getBootstrapSwatches()

Was this helpful?

Edit on Git
Export as PDF
  1. Developing
  2. Developing For ContentBox
  3. Front-End Development
  4. Theme Development

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.

/**
* loadHelpFile - helper function for loading html help into a variable for modal
* @helpFileName - the name of the file to read and return
* @helpFilePath - the relative directory for the help files. Defaulting to ./includes/help/ inside the theme.
* @return the contents of the file or empty string if the file does not exist
*/
function loadHelpFile( required string helpFileName, string helpFilePath='./includes/help/' ){
    try {
        return fileRead( arguments.helpFilePath & arguments.helpFileName );
    } catch( any e ){
        return '';
    }
}

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.

function selectMediaManagerFolder(){
    var event         = getRequestContext();
    var cbSettings     = event.getValue(name="cbSettings",private=true);
    var defaultDir = expandPath( cbSettings.cb_media_directoryRoot );
    var allDirectories = directoryList( path=defaultDir, recurse=true, listInfo="query" );
    var result = [];
    for( var directory in allDirectories ){
        if ( directory.type is 'dir' ){
            var theString = replaceNoCase( directory.directory, defaultDir, "", "all" ) & '/' & directory.name;
            theString = replaceNoCase( theString, "\", "/", "all");
            theString = replaceNoCase( theString, "//", "/", "all");
            result = result.append( theString );
        }
    }
    return result;
}

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.

array function getBootstrapStyles(){
    return [ 
        "default",
        "primary",
        "success",
        "info",
        "warning",
        "danger"
    ];
}

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.

/**
* Build the swatches options
*/
array function getBootSwatches(){
    return listToArray( "cerulean,cosmo,cyborg,darkly,flatly,green,journal,lumen,paper,readable,sandstone,simplex,slate,spacelab,superhero,united,yeti" );
}

Last updated 7 years ago

Was this helpful?