Templates API

tpl.get()

async

Gets data of template elements.

  • Accepts the template name as a string, which is the first optional argument.
    Accepts an optional second argument, which can be one of the following:
    Type
    Description
    object
    The "fields" property will contain only template elements whose values match the specified ones in the object (case-insensitive), or whose values match the specified regular expression in the object.
    array
    The "fields" property will contain only template elements with indexes corresponding to the specified numbers from the array.
    number
    The "fields" property will contain only the template element whose index corresponds to the specified number.
  • Returns an object with the following properties if a template name is passed:
    Property
    Type
    Description
    it
    DOM element
    The block element where the template elements are placed.
    fields
    array
    An array of objects with the following properties:
    Property
    Type
    Description
    it
    DOM element
    The template element.
    data
    object
    The data of the current template element.
    Returns an object whose keys are template names and whose values are template objects if no arguments are passed.
    Returns null if no blocks with template elements are found.
Example:
await tpl.get();
/*
{
   tplName: {
      it: div[data-tpl="tplName"],
      fields: [
         {
            it: div.field,
            data: {name: 'book', secondName: 'cat'}
         },
         {
            it: div.field,
            data: {name: 'book 2', secondName: 'cat 2'}
         }
      ]
   },
   'tplName:second': {
      it: div[data-tpl="tplName:second"],
      fields: []
   }
}
*/

await tpl.get('tplName');
await tpl.get('tplName', [0, 1]);
await tpl.get('tplName', {name: ['book', 'book 2']});
/*
{
   it: div[data-tpl="tplName"],
   fields: [
      {
         it: div.field,
         data: {name: 'book', secondName: 'cat'}
      },
      {
         it: div.field,
         data: {name: 'book 2', secondName: 'cat 2'}
      }
   ]
}
*/

await tpl.get('tplName', 0);
await tpl.get('tplName', {name: 'book'});
/*
{
   it: div[data-tpl="tplName"],
   fields: [
      {
         it: div.field,
         data: {name: 'book', secondName: 'cat'}
      }
   ]
}
*/

await tpl.get('tplName', {name: /2/, secondName: 'cat 2'});
/*
{
   it: div[data-tpl="tplName"],
   fields: [
      {
         it: div.field,
         data: {name: 'book 2', secondName: 'cat 2'}
      }
   ]
}
*/

await tpl.get('tplName:second');
/*
{
   it: div[data-tpl="tplName:second"],
   fields: []
}
*/

await tpl.get('tplDoesNotExist');
// null