templateLayoutFactory
Static object.
Factory for creating a layout class from a text template. Allows creating classes that implement the interface ILayout 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.
Examples:
1.
// 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.
// 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.
// 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.
// 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
Name |
Static |
Returns |
Description |
templateLayoutFactory.createClass(template[, overrides[, staticMethods]]) |
Function |
Returns layout constructor. The created class inherits from the class layout.templateBased.Base with a redefined list of methods specified in overrides. |
Methods details
createClass
{Function} _<static>_ templateLayoutFactory.createClass(template[, overrides[, staticMethods]])
Returns layout constructor. The created class inherits from the class layout.templateBased.Base with a redefined list of methods specified in overrides.
Parameters:
Parameter |
Default value |
Description |
— |
Type: String Template for HTML content for layouts. |
|
— |
Type: Object Redefining parent methods. The build, clear and rebuild methods can be redefined or expanded. |
|
— |
Type: Object Setting static methods for classes. |
* Mandatory parameter/option.
Mandatory parameter/option.