# publish

Source: https://zotonic.com/docs/2116/publish

URI: https://zotonic.com/id/2116

Language: en



Publishes a message on the topic tree of the current page.

Example:

```erlang
{% button text="Hello" action={publish topic="some/topic" js_msg="Hello World!"} %}
```

When clicked, the message set to the message `"Hello World!"` is published.

Another example, now publishing a more complex message:

```erlang
{% button text="hello" action={publish topic="some/topic" foo="bar" spam="eggs"} %}
```

When clicked, the message set to the message `{foo: "bar", spam: "eggs"}` is published.

Prefix the topic with `bridge/origin/` to relay it to the topic tree on the server.

| Argument | Description                                                     | Example                |
| -------- | --------------------------------------------------------------- | ---------------------- |
| topic    | The topic of the message.                                       | `topic="test"`         |
| js\_msg  | Literal javascript message to publish. Will be escaped.         | `js_msg="Hello World"` |
| &lt;key> | A literal javascript value, will be escaped and added to object | `spam="eggs"`          |

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/2116?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/2116?language=en>)
