home
features
quick start
download
documentation
thymol files
configuration
message resources
control parameters
expression objects
thymol types
thymol API
thymol extensions
examples
sessions
say-hello
stsm example
with-dialect
extrathyme
petclinic
news
credits
user forum
issues
browser constraints
other known issues
create new issue
thymeleaf

thymoljs

expression objects

Using Thymol 2.0 you may define custom expression utility objects that are executed in the same way as the standard dialect built-in functions (see here).

To do this, you define a JavaScript function object and configure that function for processing in accordance with the following guidelines.

function definition

A custom expression utility object needs to be defined as follows:

        var fn = function() {
        
            var thExpressionObjectName = fnHashStr;
          
            ... // Your custom function implementations and private functions here
                        
            return {
                thExpressionObjectName : thExpressionObjectName,
                ... // Exported name mappings of your custom functions here
            };
        
        }();

Where "fn" is the name of the custom expression utility object (which should be unique!) and "fnHashStr" is the name that will be used to refer to this expression object (which should also be unique!).

The value of "fn" can be any valid JavaScript identifier name.

The value of "fnHashStr" should equate to a string value and should start with a "#" character.

        var fieldsObject = function() {

            var thExpressionObjectName = "#fields";

            function hasErrors(target) {
		        return false;
            }

            function errors(target) {
		        return [];
            }
	
            return {
		        thExpressionObjectName : thExpressionObjectName,
		        hasErrors : hasErrors,
		        errors : errors
            };

        }();

function configuration

To configure this function for processing you can add an entry in a Thymol "dialectSpec" object as described here.

Alternatively, you can configure this expression object in isolation using a call to the thymol.configureModule function:

            thymol.ready(function() {
              thymol.configurePreExecution(function() {
                ...
                thymol.configureModule(fieldsObject);
                ...
              });
            });

The "#fields" object is taken from the stsm sampler example. You can see it in action here.