Skip to content

Kirby 6.0.0

Textarea

A textarea field, which auto-resizes and has built-in format buttons.

Field options

Name Type Default Description
autofocus bool false Sets the focus on this field when the form loads. Only the first field with this option gets focus
buttons arrayorbool true Enables/disables the format buttons. Can either be true/false or a list of allowed buttons. Available buttons: headlines, italic, bold, link, email, file, code, ul, ol (as well as | for a divider)
counter bool true Shows or hides the character counter in the top right corner
default mixed null Default value for the field, which will be used when a page/file/user is created
disabled bool false If true, the field is no longer editable
files mixed null Sets the options for the files picker
font string 'sans-serif' Sets the font family (sans or monospace)
help arrayorstring null Optional help text below the field
icon string null Optional icon that will be shown at the end of the field
label arrayorstring no default value The field label can be set as string or associative array with translations
maxlength int null Maximum number of allowed characters
minlength int null Minimum number of required characters
placeholder arrayorstring null Optional placeholder value that will be shown when the field is empty
required bool false If true, the field has to be filled in correctly to be saved.
size string null Changes the size of the textarea. Available sizes: small, medium, large, huge
spellcheck bool null If false, spellcheck will be switched off
translate bool true Should the field be translatable?
uploads mixed no default value Sets the upload options for linked files: a blueprint name or blueprint and parent (template is an alias for blueprint)
validate arrayorstring null Additional validator rules for the value, e.g. email or ['minLength' => 3]
when array null Conditions when the field will be shown
width string '1/1' The width of the field in the field grid. Available widths: 1/1, 1/2, 1/3, 1/4, 2/3, 3/4

The textarea field creates a textarea for longer texts with automatic resizing and optional format buttons.

Example

fields:
  text:
    label: Text
    type: textarea

Sizes

In some layouts, a small textarea looks lost. The size option sets an initial default height for empty textareas before auto-sizing kicks in. Available sizes:

  • small
  • medium
  • large
  • huge
fields:
  text:
    label: Text
    type: textarea
    size: large

Toolbar

Disabling the toolbar

If the formatting toolbar should not be available, you can switch it off entirely:

fields:
  text:
    label: Text
    type: textarea
    buttons: false

Customizing the toolbar

You can also specify which buttons to show in the toolbar.

fields:
  text:
    label: Text
    type: textarea
    buttons:
      - bold
      - '|'
      - link
      - email

You can add your custom textarea buttons in a plugin.

File upload and select

The file upload and select button is super useful if you want to embed images or other files right in your text.

You can define the button behavior with the files and uploads options:

textarea:
  type: textarea
  files: page.images
  uploads: textarea-upload

By default all files will be uploaded to the current page and without a predefined template. With the additional options you can fetch files from anywhere and upload them to specific pages. You can also control which file template should be assigned by default:

textarea:
  type: textarea
  files:
    query: site.find("media").files.template("textarea-upload")
    image:
      cover: true
  uploads:
    parent: site.find("media")
    blueprint: textarea-upload

You can also deactivate file uploads:

textarea:
  type: textarea
  uploads: false

Length restrictions

You can control the maximal and/or minimal length of the entered text by using the maxlength and/or minlength option. A handy indicator of the current text length will be displayed in the upper right corner.

fields:
  name:
    label: Name
    type: textarea
    minlength: 10
    maxlength: 1000

Monospace

You can set the font option to monospace, for example for fields that contain code:

fields:
  text:
    label: Text
    type: textarea
    font: monospace

How to use in templates/snippets

The usual way to render the value of a textarea field is using the kirbytext() method (or the shortcut kt()).

<?= $page->text()->kirbytext() ?>
<?= $page->text()->kt() ?>

However, there might be situations, where you want to parse KirbyTags, but not render block level elements:

<p><?= $page->text()->kt()->inline() ?></p>

For more field manipulations, check out Kirby's field methods.

Update programmatically

To change the field value from PHP, pass a string to $page->update():

$page->update([
  'text' => 'Some **Markdown** text'
]);