Example - Calling JS functions

Calling JS function within a template is quite easy. Just call your JS function like is a method of an object in your template context. Before calling the template function add your JS function to the template context.

Velocity template

Hello $world.name!<br/>
Today is $world.showCurrentDate();

Generated Javascript

function helloworld(context) { 
	var text = new StringCat();
	text.push('<HTML><BODY>Hello ');
	return text.toString();

Adding JS function to template context

	// adding your js function to the template context
	context.world.showCurrentDate = function() {
		return new Date();
	var html = v2js_helloworld(context);

Test it