Templates API

tpl.count()

async

Computes the count of template elements.

  • Accepts the template name, as a string, as the first argument.
    Accepts an optional second argument, which can be one of the following:
    Type
    Description
    object
    Only those template elements whose values match the specified ones in the object (case-insensitive), or whose values match the specified regular expression in the object will be considered.
    array
    Only those template elements with indexes corresponding to the specified numbers from the array will be considered.
    number
    Only the template element whose index corresponds to the specified number will be considered.
  • Returns the count of elements for the specified template name as a number.
Example:
await tpl.count();
// false

await tpl.count('tplName');
await tpl.count('tplName', [0, 1]);
await tpl.count('tplName', {name: ['book', 'book 2']});
// 2

await tpl.count('tplName', 0);
await tpl.count('tplName', {name: 'book'});
await tpl.count('tplName', {name: /2/, secondName: 'cat 2'});
// 1

await tpl.count('tplName:second');
await tpl.count('tplDoesNotExist');
// 0