Skip to content

Kirby 6.0.0

Writer

A simple WYSIWYG editor field for inline content with formats like bold, italic, etc.

Field options

Name Type Default Description
after arrayorstring null Optional text that will be shown after the input
autofocus bool false Sets the focus on this field when the form loads. Only the first field with this option gets focus
before arrayorstring null Optional text that will be shown before the input
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
headings array [1, 2, 3, 4, 5, 6] Available heading levels
help arrayorstring null Optional help text below the field
icon string null Optional icon that will be shown at the end of the field
inline bool false Enables inline mode, which will not wrap new lines in paragraphs and creates hard breaks instead.
label arrayorstring no default value The field label can be set as string or associative array with translations
marks arrayorbool null Sets the allowed HTML formats. Available formats: bold, italic, underline, strike, code, link, email. Activate/deactivate them all by passing true/false. Default marks are bold, italic, underline, strike, link, email
maxlength int null Maximum number of allowed characters
minlength int null Minimum number of required characters
nodes arrayorbool null Sets the allowed nodes. Available nodes: paragraph, heading, bulletList, orderedList, quote. Activate/deactivate them all by passing true/false. Default nodes are paragraph, heading, bulletList, orderedList.
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.
spellcheck bool null If false, spellcheck will be switched off
toolbar arrayorbool null Toolbar options, incl. marks (to narrow down which marks should have toolbar buttons), nodes (to narrow down which nodes should have toolbar dropdown entries) and inline to set the position of the toolbar (false = sticking on top of the field)
translate bool true Should the field be translatable?
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

Example

fields:
  text:
    label: Writer
    type: writer

Marks

The writer field supports the following marks by default:

  • bold
  • italic
  • underline
  • strike
  • code
  • link
  • email
  • sub
  • sup
  • clear

The special mark | can be used to separate marks in the toolbar by a vertical line.

fields:
  text:
    type: writer
    inline: true
    marks:
      - bold
      - italic
      - '|'
      - strike

You can extend Kirby to include custom marks.

Nodes

Apart from paragraph nodes, the writer field supports lists, headings, horizontal rules and quotes. You can fine-tune the writer field from your blueprint by defining the available block formats (nodes).

The writer field supports the following nodes by default:

  • paragraph
  • bulletList
  • orderedList
  • heading
  • horizontalRule
  • quote

Unsupported formats will automatically be ignored when content is pasted and the toolbar will also not include the matching buttons.

fields:
  writer:
    type: writer
    nodes:
      - heading
      - bulletList
      - orderedList

You can extend Kirby to include custom nodes.

Toolbar

The toolbar option allows you to customize the writer's toolbar:

text:
  type: writer
  marks:
    - bold
    - italic
    - link
    - code
  toolbar:
    inline: false
    marks:
      - bold
      - "|"
      - link
  • inline attaches the toolbar to the top of the field (instead of the floating pill style)
  • marks and nodes control which marks and nodes are shown in the toolbar. Make sure that the ones you want to include are actually active and not excluded in the top-level marks and nodes options (see above). The top-level options define which ones are supported, the toolbar-level options what is shown as buttons in the toolbar. For example, you might want to support the code mark for pasting, but hide it from the toolbar.

Inline mode

By default, the writer field will supports multiple paragraphs (<p>). In inline mode, hitting enter will create breaks instead of creating a new paragraph.

fields:
  text:
    type: writer
    inline: true

In inline mode, all nodes (see above) are disabled.

Heading levels

You can set the available heading levels in the writer field with the headings option:

fields:
  text:
    type: writer
    headings:
      - 2
      - 3
      - 4

How to use in templates/snippets

The content of the writer field is stored as plain HTML. To render the field in your template, echo the value.

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

Update programmatically

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

$page->update([
  'text' => '<p>Some <strong>bold</strong> text</p>'
]);

Kirby sanitizes the HTML before storing it, e.g. <script> tags are removed.