Skip to content

textarea_control

The textarea_control macro is used to render a textarea control. It it used by the textarea macro but can also be used alone to have more control over how the switch is being rendered.

Definition

{% textarea_control(options) %}

Input parameters

options

object parameter represents an object of textarea control options and attributes

Option key Type Default Required Description
options.id string "" yes Id attribute of the textarea
options.name string "" yes Name attribute of the textarea
options.disabled boolean false no If set to true, disabled attribute will be added to textarea
options.required boolean false no If set to true, required attribute will be added to textarea
options.readonly boolean false no If set to true, readonly attribute will be added to textarea
options.hidden boolean false no If set to true, hidden attribute will be added to textarea
options.value string "" no Value attribute of the textarea
options.placeholder string "" no Placeholder attribute of the textarea

Example

In this example we render a basic textarea control. In all examples we will also use additional control classes and elements that help to style the textarea properly.

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

<div class="control">
    <div class="control__content">
        <div class="control__element">
            <div class="textarea">
                {{ textarea_control({
                    id: 'comment',
                    name: 'comment'
                }) }}
            </div>
        </div>
    </div>
</div>

Example

In this example we render a required textarea control with a custom placeholder.

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

<div class="control">
    <div class="control__content">
        <div class="control__element">
            <div class="textarea">
                {{ textarea_control({
                    id: 'comment',
                    name: 'comment',
                    required: true,
                    placeholder: 'Enter a comment...'
                }) }}
            </div>
        </div>
    </div>
</div>

Example

In this example we render a hidden and required textarea control with a custom value.

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

<div class="control">
    <div class="control__content">
        <div class="control__element">
            <div class="textarea">
                {{ textarea_control({
                    id: 'comment',
                    name: 'comment',
                    hidden: true,
                    required: true,
                    value: 'My comment'
                }) }}
            </div>
        </div>
    </div>
</div>

Macro source code

{% macro textarea_control(options) %}
    <textarea
        id="{{ options.id }}"
        name="{{ options.name }}"
        class="textarea__control"

        {% if options.placeholder is defined %}
            placeholder="{{ options.placeholder }}"
        {% endif %}

        {% if options.required %}required{% endif %}
        {% if options.hidden %}hidden{% endif %}
        {% if options.disabled %}disabled{% endif %}
        {% if options.readonly %}readonly{% endif %}
    >{% if options.value is defined %}{{ options.value }}{% endif %}</textarea>
{% endmacro %}

Form reference