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

# The layout of the placemark balloon

<iframe id="LIVE-EXAMPLE" style="width:100%;height: 400px;border-radius: 8px;border: 1px solid rgba(92, 94, 102, 0.14);" frameBorder="0" src="https://yastatic.net/s3/front-maps-static/maps-front-jsapi-v2-1/examples/2/out/s3-cases/en/placemark_balloon_layout/index.html" allow="fullscreen"></iframe>

<a target="_blank" rel="noopener noreferrer" style="display: inline-block;margin-top: 10px;cursor: pointer;border-radius: 4px;padding: 9px 12px;background: #151515;color: white;text-decoration: none;font-weight: 500" href="https://codesandbox.io/p/sandbox/9kywjw?file=index.html">Open in CodeSandbox</a>

<div id="references">
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ready">ready</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Map">Map</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Placemark">Placemark</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/templateLayoutFactory">templateLayoutFactory</a>
</div>
<p>
    Object layouts can be created using the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/templateLayoutFactory">templateLayoutFactory</a> factory and
    text templates.
</p>
<p>
    This example creates a custom balloon layout for a <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObject">geo object</a>.
    The layout is set for the geo object via options.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>

    <html>
        <head>
            <title>Examples. The layout of a geo object's balloon.</title>
            <meta
                http-equiv="Content-Type"
                content="text/html; charset=UTF-8"
            />
            <!--
            Set your own API-key. Testing key is not valid for other web-sites and services.
            Get your API-key on the Developer Dashboard: https://developer.tech.yandex.ru/keys/
        -->
            
            
            
            
        </head>

        <body>
            <div id="map"></div>
        </body>
    </html>
    ```

-   placemark_balloon_layout.js

    ```js
    ymaps.ready(init);

    function init() {
        var map = new ymaps.Map(
                "map",
                {
                    center: [55.650625, 37.62708],
                    zoom: 10,
                },
                {
                    searchControlProvider: "yandex#search",
                }
            ),
            counter = 0,
            /**
             * Creating a balloon content layout.
             *  The layout is created using the layout factory and a text template.
             */
            BalloonContentLayout = ymaps.templateLayoutFactory.createClass(
                '<div style="margin: 10px;">' +
                    "<b>{{properties.name}}</b><br />" +
                    '<i id="count"></i> ' +
                    '<button id="counter-button"> +1 </button>' +
                    "</div>",
                {
                    /**
                     * Redefining the "build" function in order to start listening to the "click" event
                     * on a counter button when creating the layout.
                     */
                    build: function () {
                        // First, we call the "build" method of the parent class.
                        BalloonContentLayout.superclass.build.call(this);
                        // Then we perform additional steps.
                        $("#counter-button").bind("click", this.onCounterClick);
                        $("#count").html(counter);
                    },

                    /**
                     * In the same way, we redefine the "clear" function in order to
                     * remove listening for clicks when the layout is deleted from the map.
                     */
                    clear: function () {
                        /**
                         * We perform the steps in reverse order - first remove the listener,
                         * and then call the "clear" method of the parent class.
                         */
                        $("#counter-button").unbind(
                            "click",
                            this.onCounterClick
                        );
                        BalloonContentLayout.superclass.clear.call(this);
                    },

                    onCounterClick: function () {
                        $("#count").html(++counter);
                        if (counter == 5) {
                            alert("Good work.");
                            counter = 0;
                            $("#count").html(counter);
                        }
                    },
                }
            );

        var placemark = new ymaps.Placemark(
            [55.650625, 37.62708],
            {
                name: "Calculating",
            },
            {
                balloonContentLayout: BalloonContentLayout,
                /**
                 * Disabling replacing the normal balloon with the balloon panel.
                 * If you do not specify this option, the balloon panel opens on small maps.
                 */
                balloonPanelMaxMapArea: 0,
            }
        );

        map.geoObjects.add(placemark);
    }
    ```

{% endlist %}
