> 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-show.md).

# wire:show

Livewire's `wire:show` directive makes it easy to show and hide elements based on the result of an expression.

The `wire:show` directive is different than using conditionals in your template in that it toggles an element's visibility using CSS (`display: none`) rather than removing the element from the DOM entirely. This means the element remains in the page but is hidden, allowing for smoother transitions without requiring a server round-trip.

## Basic Usage

Here's a practical example of using `wire:show` to toggle a "Create Post" modal:

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

```javascript
// wires/CreatePost.bx
class extends="cbwire.models.Component" {
    data = {
        "showModal": false,
        "content": ""
    };

    function save() {
        getInstance("Post").create({ "content": data.content });

        reset("content");

        data.showModal = false;
    }
}
```

{% endtab %}

{% tab title="CFML" %}

```javascript
// wires/CreatePost.cfc
component extends="cbwire.models.Component" {
    data = {
        "showModal" = false,
        "content" = ""
    };

    function save() {
        getInstance("Post").create({ "content" = data.content });

        reset("content");

        data.showModal = false;
    }
}
```

{% endtab %}
{% endtabs %}

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

```html
<!-- wires/createPost.bxm -->
<bx:output>
<div>
    <button x-on:click="$wire.showModal = true">New Post</button>

    <div wire:show="showModal">
        <form wire:submit="save">
            <textarea wire:model="content"></textarea>

            <button type="submit">Save Post</button>
        </form>
    </div>
</div>
</bx:output>
```

{% endtab %}

{% tab title="CFML" %}

```html
<!-- wires/createPost.cfm -->
<cfoutput>
<div>
    <button x-on:click="$wire.showModal = true">New Post</button>

    <div wire:show="showModal">
        <form wire:submit="save">
            <textarea wire:model="content"></textarea>

            <button type="submit">Save Post</button>
        </form>
    </div>
</div>
</cfoutput>
```

{% endtab %}
{% endtabs %}

When the "New Post" button is clicked, the modal appears without a server roundtrip. After successfully saving the post, the modal is hidden and the form is reset.

## Using Transitions

You can combine `wire:show` with Alpine.js transitions to create smooth show/hide animations. Since `wire:show` only toggles the CSS display property, Alpine's `x-transition` directives work perfectly with it:

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

```html
<!-- wires/createPost.bxm -->
<bx:output>
<div>
    <button x-on:click="$wire.showModal = true">New Post</button>

    <div wire:show="showModal" x-transition.duration.500ms>
        <form wire:submit="save">
            <textarea wire:model="content"></textarea>
            <button type="submit">Save Post</button>
        </form>
    </div>
</div>
</bx:output>
```

{% endtab %}

{% tab title="CFML" %}

```html
<!-- wires/createPost.cfm -->
<cfoutput>
<div>
    <button x-on:click="$wire.showModal = true">New Post</button>

    <div wire:show="showModal" x-transition.duration.500ms>
        <form wire:submit="save">
            <textarea wire:model="content"></textarea>
            <button type="submit">Save Post</button>
        </form>
    </div>
</div>
</cfoutput>
```

{% endtab %}
{% endtabs %}

The Alpine.js transition classes above will create a fade and scale effect when the modal shows and hides.

{% hint style="info" %}
For more information on Alpine.js transitions, visit the [Alpine.js x-transition documentation](https://alpinejs.dev/directives/transition).
{% endhint %}


---

# 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-show.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.
