# Toggle

This block type renders a toggle link that sends an AJAX request on every subsequent click, changing its icon and label depending on the current state.

### Parameters

* **view** - the link view, set to `icon` if labels are not required;
* **url** - the URL for sending AJAX requests on click;
* **states** - an array of the link state parameters;
* **attributes** - the link HTML attributes;
* **active** - `true` if the toggle link is currently active.

### Example

The code below renders a toggle link that displays the "Follow" text with the `user-plus` [Font Awesome](https://fontawesome.com/v6/icons/) icon when inactive and the "Unfollow" text with the `user-minus` icon when active. It sends an AJAX request to the `https://example.com` URL, changing the link icon and label on every subsequent click.

```php
echo ( new HivePress\Blocks\Toggle(
	[
		'url'    => 'https://example.com',

		'states' => [
			[
				'icon'    => 'user-plus',
				'caption' => 'Follow',
			],
			[
				'icon'    => 'user-minus',
				'caption' => 'Unfollow',
			],
		],
	]
) )->render();
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hivepress.io/developer-docs/framework/blocks/toggle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
