I want to loop through the array of markers and place these marks on the map using the template engine

 ymaps.ready(init); var myMap, markers = [{ lat: 55.2049, lon: 30.1843, name: 'Имя 1', address: 'Адрес1', phone: '+322-32-11-22-33' hintContent: '<h3>This is Hint 1</h3>' }, { lat: 54.80077688, lon: 32.00807933, name: 'Имя 2', address: 'Адрес 2', phone: '+322-32-55-66-111', hintContent: '<h3>This is Hint 2</h3>' } ]; function init() { myMap = new ymaps.Map("map", { center: [55.18, 30.23], zoom: 5, controls: ['routeButtonControl'], behaviors: ['drag'] }); markers.forEach(function(m){ var marker = new ymaps.Placemark( [m.lat, m.lon], { name: m.name, address: m.address, phone: m.phone, hintContent: m.hintContent }, { balloonContentLayout: BalloonContentLayoutClass } ); myMap.geoObjects.add(marker); }); var BalloonContentLayoutClass = ymaps.templateLayoutFactory.createClass( '<h3>{{ properties.name }}</h3>' + '<p>{{ properties.address }}</p>' + '<p>{{ properties.phone }}</p>' + ); ` 

Tags are placed, hint is visible, there is no balun. ((If the loop is not used, then the static data works normally.

 `var marker = new ymaps.Placemark( [55.8, 37.6], { name: 'Имя', address: 'Адрес', phone: '+7 (222) 555-44-33', }, { balloonContentLayout: MyBalloonContentLayoutClass } ); myMap.geoObjects.add(marker);` 

Sorrow

    1 answer 1

    The variable BalloonContentLayoutClass is declared after use:

     balloonContentLayout: BalloonContentLayoutClass 

    . . .

     var BalloonContentLayoutClass = ymaps.templateLayoutFactory.createClass( '<h3>{{ properties.name }}</h3>' + '<p>{{ properties.address }}</p>' + '<p>{{ properties.phone }}</p>' ); 

    http://jsfiddle.net/du0zjcyh/

    • Thank you very much. I can’t add a paragraph - there is no reputation)) - Pavel L
    • PS: is there a way to get such errors from the API? so that the console was written, for example, not defined and not to blunt it anymore? Thanks again. )) - Pavel L
    • one
      During the debugging process, it is often useful to add api mode = debug jsfiddle.net/d87nr4bg to the connection . But in this case it does not help, because this is more like the logical error of your code. This is a valid operation and is equivalent to balloonContentLayout: undefined, which is equivalent to options.unset ('balloonContentLayout'). Which is similar to "I do not want to bark at the content of a balun." - se0ga