> For the complete documentation index, see [llms.txt](https://openjs.wiki.gd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openjs.wiki.gd/openjs-components/interacting-with-external-plugins/placeholderapi.md).

# PlaceHolderApi integration

## Using placeholders in scripts

{% hint style="warning" %}
**To ensure PlaceholderAPI integration for any script, add the** [**feature flag**](/openjs-components/fflags.md)**:**

```js
//!PlaceholderAPI
```

{% endhint %}

#### Method

```js
PlaceholderAPI.parseString(player: Player, input: String): String
```

**Parameters:**

* **player** (`Player`):\
  The player for whom the placeholder should be parsed.
* **input** (`String`):\
  The string containing one or more placeholders (e.g., `%placeholder%` ).

**Returns:**

* `String`:\
  A copy of the input string with all placeholders replaced with their actual values.

***

#### Example

{% code title="Example:" %}

```javascript
registerEvent("org.bukkit.event.player.PlayerJoinEvent", {
    handleEvent: function(event) {
        var player = event.getPlayer()
        var message = "Placeholder data: %placeholder%"
        var parsedMsg = PlaceholderAPI.parseString(player, message)
        player.sendMessage(parsedMsg)
    }
})
```

{% endcode %}

## Creating placeholders with scripts

**Method:** `PlaceholderAPI.registerPlaceholder(prefix, listener)`&#x20;

* **prefix** (`String`):\
  The unique identifier for your placeholder. It will be used in the placeholder format `%openjs_<prefix>_<params>%`
* **listener** (`Object`):\
  An object containing an `onRequest(player, params)` method, which will be called whenever the placeholder is parsed

**Parameter:** `onRequest(player: Player | null, params: String | null): String`

* **player** (`Player | null`)  \
  The player for whom the placeholder is being resolved. Can be null (e.g., if not run in a player context)
* **params** (`String | null`)  \
  The parameter string following your prefix in the placeholder. Can also be null.

#### Placeholder Syntax

```javascript
%openjs_<prefix>_<params>%
```

***

* Example: `%openjs_greetplr_to this server!%`
  * Prefix: `greetplr`
  * Params: `to this server!`

{% code title="Example:" %}

```javascript
//!PlaceholderAPI

// Register a custom placeholder %openjs_greetplr_<params>%
PlaceholderAPI.registerPlaceholder("greetplr", {
    onRequest: function(player, params) {
        return "Welcome " + player.getName() + " " + params;
    }
});

registerEvent("org.bukkit.event.player.PlayerJoinEvent", {
    handleEvent: function(event) {
        var player = event.getPlayer();
        var rawMessage = "%openjs_greetplr_to this server!%";
        var parsedMessage = PlaceholderAPI.parseString(player, rawMessage);
        player.sendMessage(parsedMessage); // → Welcome Steve to this server!
    }
});

```

{% endcode %}

***

## Removing placeholders with scripts

```js
PlaceholderAPI.unregisterPlaceholder(prefix: String)
```

**Parameters:**

* **prefix** (`String`):\
  The unique identifier for your placeholder. It will be used in the placeholder format `%openjs_<prefix>_<params>%`

{% code title="Example:" %}

```javascript
//!PlaceholderAPI

// Register a custom placeholder %openjs_greetplr_<params>%
PlaceholderAPI.registerPlaceholder("greetplr", {
    onRequest: function(player, params) {
        return "Welcome " + player.getName() + " " + params;
    }
});

// Removing the custom placeholder %openjs_greetplr_<params>%:
PlaceholderAPI.unregisterPlaceholder("greetplr")
```

{% endcode %}


---

# 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://openjs.wiki.gd/openjs-components/interacting-with-external-plugins/placeholderapi.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.
