> For the complete documentation index, see [llms.txt](https://cbwire.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cbwire.ortusbooks.com/template-directives/wire-text.md).

# wire:text

`wire:text` is a directive that dynamically updates an element's text content based on a component property or expression. Unlike using template output syntax, `wire:text` updates the content without requiring a network roundtrip to re-render the component.

If you are familiar with Alpine's `x-text` directive, the two are essentially the same.

## Basic Usage

Here's an example of using `wire:text` to optimistically show updates to a Livewire property without waiting for a network roundtrip.

{% tabs %}
{% tab title="BoxLang" %}

```javascript
// wires/ShowPost.bx
class extends="cbwire.models.Component" {
    data = {
        "postId": 0,
        "likes": 0
    };

    function onMount( params ) {
        data.postId = params.postId;

        var post = getInstance("Post").findOrFail(data.postId);
        data.likes = post.getLikeCount();
    }

    function like() {
        var post = getInstance("Post").findOrFail(data.postId);
        post.like();

        data.likes = post.fresh().getLikeCount();
    }
}
```

{% endtab %}

{% tab title="CFML" %}

```javascript
// wires/ShowPost.cfc
component extends="cbwire.models.Component" {
    data = {
        "postId" = 0,
        "likes" = 0
    };

    function onMount( params ) {
        data.postId = params.postId;

        var post = getInstance("Post").findOrFail(data.postId);
        data.likes = post.getLikeCount();
    }

    function like() {
        var post = getInstance("Post").findOrFail(data.postId);
        post.like();

        data.likes = post.fresh().getLikeCount();
    }
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="BoxLang" %}

```html
<!-- wires/showPost.bxm -->
<bx:output>
<div>
    <button x-on:click="$wire.likes++" wire:click="like">❤️ Like</button>

    Likes: <span wire:text="likes"></span>
</div>
</bx:output>
```

{% endtab %}

{% tab title="CFML" %}

```html
<!-- wires/showPost.cfm -->
<cfoutput>
<div>
    <button x-on:click="$wire.likes++" wire:click="like">❤️ Like</button>

    Likes: <span wire:text="likes"></span>
</div>
</cfoutput>
```

{% endtab %}
{% endtabs %}

When the button is clicked, `$wire.likes++` immediately updates the displayed count through `wire:text`, while `wire:click="like"` persists the change to the database in the background.

This pattern makes `wire:text` perfect for building optimistic UIs in Livewire.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cbwire.ortusbooks.com/template-directives/wire-text.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
