This class renders an Apache Velocity template. For Velocity template syntax, see
Velocity 1.7.
The render() methods identify the template to render from:
- a template file name, which is resolved in the Dynamic WebDAV file location for the current site.
Template file names must end with either '.vm' or '.vs'.
- a dw.io.File object, which can point to any file system location that is accessible from a script
- a string that holds the template content directly
Note: Files included from an ISML template (either via
#parse
or
#include
) are always resolved
in the Dynamic location, and it is not possible to provide an absolute path.
On the target side of rendering, by default the render() methods write to the current response writer. When needed,
a
dw.io.Writer
can be supplied as a target.
Parameters for rendering can be passed as a single object holding the parameters as properties.
To create a URL, pass the
URLUtils
class.
To access localized strings, pass the
Resource
class:
var urlUtil = require('dw/web/URLUtils');
velocity.render("$url.abs('Foo-Bar','cgid',$res.msg('key')", {'url' : urlUtil, 'res' : dw.web.Resource});
The complete set of
VelocityTools
are provided to the template. You can use the tools to escape dynamic data, format text, and for other common tasks.
Template files are cached for different amounts of time, depending on the instance type.