@text

Add editable plain text areas to your components

The @text directive creates an editable plain text area within your component. This is ideal for headings, labels, button text, and any single-line or simple multi-line text content.

Syntax

@text("identifier")

Or with additional parameters:

@text(name: "identifier", title: "Display Title", default: "Default text")

Parameters

Parameter
Required
Description

name

Yes

A unique identifier for the text area within the component

title

No

The label displayed in the editor interface

default

No

Default text to display when no content has been entered

Examples

Basic Text Area

Create a simple editable text area:

<h1>@text("heading")</h1>

With Default Value

Provide default text that users can modify:

With Title for Editor

Add a descriptive title that appears in the editor interface:

Button with Conditional Text

Combine @text with conditionals to show text only when enabled:

Form Labels

Using @text Inside an @each Loop

You can use the @text directive inside an @each loop to create unique editable text areas for each iteration. The loop index is automatically appended to the identifier, ensuring each text area remains distinct:

In this example, if the loop iterates three times, it will create three unique text areas, each independently editable.

Best Practices

  1. Use descriptive identifiers - Choose names that clearly indicate the text's purpose (e.g., "heading", "buttonLabel", "siteTitle").

  2. Provide helpful defaults - Default text helps users understand the expected content and provides a starting point.

  3. Add titles for clarity - The title parameter helps users identify the text area in the editor, especially when there are multiple text areas.

  4. Use for simple content - For rich formatting needs, consider @richtext or @markdown instead.

  • @richtext - For styled text with Typography support

  • @markdown - For Markdown-formatted content

Last updated

Was this helpful?