Skip to content

checkbox

The checkbox macro is used to render checkbox control. Internally is uses checkbox_control macro and checkbox_content macro.

Definition

{% checkbox(options) %}

Input parameters

options

object represents an object of input attributes

Option key Type Default Required Description
options.id string "" yes checkox id attribute
options.name string "" yes checkox name attribute
options.error boolean false no if true checkbox is in error mode
options.checked boolean false no if true checkbox is checkced
options.disabled boolean false no if true checkbox is disabled
options.required boolean false no if true checkbox is required
options.readonly boolean false no if true checkbox is readonly
options.value string "" no checkbox value
options.label string "" no checkbox label
options.description string "" no description below label
options.partiallyChecked boolean false no if true checkbox is in partially checked state

Example

{% from "@macros/checkbox.twig" import checkbox %}

<div class="control">
    <div class="control__content">
        <div class="control__element">
            {{ 
                checkbox({
                    id: 'agreement',
                    name: 'agreement',
                    value: '1',
                    checked: true
                }) 
            }}
        </div>
    </div>
</div>

Macro source code

{% macro checkbox(options) %}
    {% from "@macros/checkbox_control.twig" import checkbox_control %}
    {% from "@macros/checkbox_content.twig" import checkbox_content %}

    <div class="checkbox {% if options.error %}checkbox_error{% endif %} {% if options.disabled %}checkbox_disabled{% endif %}">
        {{ checkbox_control(options) }}
        {{ checkbox_content(options) }}
    </div>
{% endmacro %}

Form reference