---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/templateLayoutFactory.md
  - https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/templateLayoutFactory.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.ru/dev/jsapi-v2-1/doc/en/llms.txt

# templateLayoutFactory

Static object.

Factory for creating a layout class from a text template. Allows creating classes that implement the interface [ILayout](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILayout.md) using a template language. The Yandex Maps API supports the base syntax for the Twig/Django Templates languages. For more information about the syntax, see the description of the [Template](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Template.md).

**See** [layout.templateBased.Base](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/layout.templateBased.Base.md)

[Methods](#methods-summary)

**Examples:**

**1.**

```javascript
// In this example, the value of the "colorClass" option and the value of the "header" property are added to the layout. 
// If the "header" property doesn't have a value, the string "Title" is inserted.
var LayoutClass = ymaps.templateLayoutFactory.createClass(
    '<h1 class="{{ options.colorClass }}">' +
    '{{ properties.header|default:"Title" }}' +
    '</h1>'
);
```

**2.**

```javascript
// One of the layouts is enabled, depending on the value of the "width" option.
var LayoutClass = ymaps.templateLayoutFactory.createClass(
    '{% if options.width > 200 %}' +
    // The appropriate layout will be found in the options.
    '{% include options.wideLayout %}' +
    '{% else %}' +
    // Writing the key explicitly.
    '{% include "cluster#balloonCarousel" %}' +
    '{% endif %}'
);
```

**3.**

```javascript
// Outputting an array of names to the balloon layout.
var CustomLayoutClass = ymaps.templateLayoutFactory.createClass(
    '<ul>' +
    '{% for name in properties.names %}' +
    // The "name" variable is only visible in the for ... endfor block
    '<li>{{ name }}</li>' +
    '{% endfor %}' +
    '</ul>'
);

var placemark = new ymaps.Placemark([54.83, 37.11], { 
    names: ['Logan', 'Sofia', 'Mason', 'Layla']
}, {
    balloonContentLayout: CustomLayoutClass
});
```

**4.**

```javascript
// Getting the names of fields.
var CustomLayoutClass = ymaps.templateLayoutFactory.createClass(
    '<ul>' +
    '{% for key, value in properties.hash %}' +
    '<li>{{ key }} {{ value }}</li>' +
    '{% endfor %}' +
    '</ul>'
);

var placemark = new ymaps.Placemark([54.83, 37.11], { 
    hash: { key1: "value1", key2: "value2", key3: "value3" }
}, {
    balloonContentLayout: CustomLayoutClass
});
```

## Methods {#methods-summary}

#|
|| **Name** | **Static** | **Returns** | **Description** ||
|| templateLayoutFactory.[createClass](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/templateLayoutFactory.md#.createClass)([template](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/templateLayoutFactory.md#createClass-param-template)[, [overrides](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/templateLayoutFactory.md#createClass-param-overrides)[, [staticMethods](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/templateLayoutFactory.md#createClass-param-staticMethods)]]) | ![](../_images/check.png) | Function | Returns layout constructor. The created class inherits from the class [layout.templateBased.Base](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/layout.templateBased.Base.md) with a redefined list of methods specified in overrides.||
|#

## Methods details {#method_detail}

### createClass {#createClass}

```javascript
{Function}  _<static>_ templateLayoutFactory.createClass(template[, overrides[, staticMethods]])
```

**Returns** layout constructor. The created class inherits from the class [layout.templateBased.Base](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/layout.templateBased.Base.md) with a redefined list of methods specified in overrides.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`template`](#createClass-param-template)[*](*star) | — | Type: String

Template for HTML content for layouts. ||
|| [`overrides`](#createClass-param-overrides) | — | Type: Object

Redefining parent methods. The build, clear and rebuild methods can be redefined or expanded. ||
|| [`staticMethods`](#createClass-param-staticMethods) | — | Type: Object

Setting static methods for classes. ||
|#

\* Mandatory parameter/option.

[*star]: Mandatory parameter/option.