May 25, 2021 Grunt
Template functions can be called manually to handle template strings.
In addition, the config.get method , which is used by many tasks, automatically parses the template string of the
<% %>
Gruntfile
Handles a
Lo-Dash template
string.
template
parameter is recursively processed and knows that there is no template location.
The default data object is the entire configuration object, but is
options.data
is set.
The default template separator is
<% %>
but if
options.delimiters
set to a custom form (set by
grunt.template.addDelimiters
this template separator is used later.
grunt.template.process(template [, options])
The grunt object
grunt
inside the template, so you can do this
<%= grunt.template.tody('yyyy') %>
te.
grunt
the grunt API will not be
grunt
template.
In the following case, the
baz
is recursively processed until there is no redundant
<% %>
be processed.
var obj = {
foo: 'c',
bar: 'b<%= foo %>d',
baz: 'a<%= bar %>e'
};
grunt.template.process('<%= baz %>', {data: obj}) // 'abcde'
Set
the separator for the Lo-Dash
template in a predefined form in case you need to
grunt.util._.template
config
separator
<% %>
.
You may never use this method because you
grunt.template.process
internally.
grunt.template.setDelimiters(name)
Add
a named separator
to the Lo-Dash template.
You may not need to use this method because the built-in split character
[% %]
should be sufficient, but you can still add a separator in the style of
{% %}
or .
name
parameter should be unique, because this is also how we
grunt.template.setDelimiters
and is subsequently used as an option
grunt.template.process
grunt.template.addDelimiters(name, opener, closer)
In this instance, if we want to use
{% %}
of . . . % , we need to set it like this:
grunt.template.addDelimiters('myDelimiters', '{%', '%}')
Format a date with dateformat library.
grunt.template.date(date, format)
In this case, the specified date is formatted as month/day/year.
grunt.template.date(847602000000, 'yyyy-mm-dd') // '1996-11-10'
Format the current date with dateformat library.
grunt.template.today(format)
In this case, the current date is formatted as a year represented by a 4-digit number.
grunt.template.today('yyyy') // '2014'