---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.ru/dev/maps/archive/doc/jsapi/2-0/ru/examples/cases/button_layout.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.ru/dev/maps/archive/doc/jsapi/2-0/ru/llms.txt

# Макет кнопки

<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-0/examples/1/out/s3-cases/ru/button_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/rw5fzf?file=index.html">Open in CodeSandbox</a>

<div id="doc">
    <div id="references">
        <a href="https://yandex.ru/dev/maps/archive/doc/jsapi/2-0/ru/ref/reference/ready">ready</a>, <a href="https://yandex.ru/dev/maps/archive/doc/jsapi/2-0/ru/ref/reference/Map">Map</a>,
        <a href="https://yandex.ru/dev/maps/archive/doc/jsapi/2-0/ru/ref/reference/control.Button">control.Button</a>, <a href="https://yandex.ru/dev/maps/archive/doc/jsapi/2-0/ru/ref/reference/templateLayoutFactory">templateLayoutFactory</a>
    </div>
    <p>
        <a href="https://yandex.ru/dev/maps/archive/doc/jsapi/2-0/ru/dg/concepts/layouts">Макеты</a>
        объектов можно создавать с помощью фабрики <a href="https://yandex.ru/dev/maps/archive/doc/jsapi/2-0/ru/ref/reference/templateLayoutFactory">templateLayoutFactory</a>,
        используя текcтовые шаблоны.
    </p>
    <p>
        В данном примере создается пользовательский макет <a href="https://yandex.ru/dev/maps/archive/doc/jsapi/2-0/ru/ref/reference/control.Button">кнопки</a>.
        Макет элемента управления строится на основе его данных, состояния и опций.
    </p>
    <p>
        Макет автоматически перестраивается при изменении значений полей,
        состояния или опций, которые используются в его текстовом шаблоне.
    </p>
</div>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>

    <html>
        <head>
            <title>Примеры. Пользовательский макет кнопки.</title>
            <meta
                http-equiv="Content-Type"
                content="text/html; charset=utf-8"
            />
            <!--
            Укажите свой API-ключ. Тестовый ключ НЕ БУДЕТ работать на других сайтах.
            Получить ключ можно в Кабинете разработчика: https://developer.tech.yandex.ru/keys/
        -->
            
            

            
        </head>

        <body>
            <div id="map" style="width:400px; height:300px"></div>
        </body>
    </html>
    ```

-   button_layout.js

    ```js
    ymaps.ready(init);

    function init() {
        var myMap = new ymaps.Map("map", {
                center: [55.650625, 37.62708],
                zoom: 10,
            }),
            // Макет кнопки должен отображать поле data.content
            // и изменяться в зависимости от того, нажата кнопка или нет.
            ButtonLayout = ymaps.templateLayoutFactory.createClass(
                "<div class='my-button [if state.selected]my-button-selected[endif]'>" +
                    "$[data.content]" +
                    "</div>"
            ),
            button = new ymaps.control.Button(
                {
                    data: {
                        content: "Жмак-жмак",
                    },
                },
                {
                    layout: ButtonLayout,
                }
            );

        myMap.controls.add(button, {
            right: 5,
            top: 5,
        });
    }
    ```

{% endlist %}
