# ToolbarRenderer

> Renders shared toolbar views and resolves their assets through Yii2.

[API reference](/docs/api/index.md) › [Debug](/docs/extensions/debug/reference/index.md) › ToolbarRenderer

| final readonly class | `yii\debug\ToolbarRenderer` |
| --- | --- |
| Source | [`src/ToolbarRenderer.php`](https://github.com/yii2-extensions/debug/blob/main/src/ToolbarRenderer.php#L17) |

Renders shared toolbar views and resolves their assets through Yii2.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Binds toolbar rendering to the Yii view, asset publisher and template path. | `ToolbarRenderer` |
| [`inject()`](#method-inject) | Injects toolbar markup immediately before the final closing body tag. | `ToolbarRenderer` |
| [`renderElement()`](#method-renderElement) | Renders the framework-neutral toolbar template through the Yii2 view component. | `ToolbarRenderer` |
| [`scriptTag()`](#method-scriptTag) | Renders a script tag for the Yii2-published toolbar runtime. | `ToolbarRenderer` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(yii\base\View $view, yii\web\AssetManager $assetManager, string $viewPath)
```

Binds toolbar rendering to the Yii view, asset publisher and template path.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$view` | [`yii\base\View`](/docs/api/yii/base/view/index.md) | Yii2 PHP view renderer. |
| `$assetManager` | [`yii\web\AssetManager`](/docs/api/yii/web/assetmanager/index.md) | Yii2 asset publisher. |
| `$viewPath` | `string` | Shared toolbar template path or alias. |

### inject() <span id="method-inject"></span>

```php
public function inject(string $html, string $toolbar): string
```

Injects toolbar markup immediately before the final closing body tag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$html` | `string` | Response HTML. |
| `$toolbar` | `string` | Rendered toolbar markup. |

**Returns**

`string`: HTML containing the toolbar, appended when no closing body tag exists.

### renderElement() <span id="method-renderElement"></span>

```php
public function renderElement(string $dataUrl, list<string> $skipUrls = [], string $position = 'bottom', int $height = 50): string
```

Renders the framework-neutral toolbar template through the Yii2 view component.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$dataUrl` | `string` | Toolbar payload URL. |
| `$skipUrls` | `list<string>` | Same-origin URLs excluded from AJAX tracking. |
| `$position` | `string` | Initial toolbar position. |
| `$height` | `int` | Initial drawer height percentage. |

**Returns**

`string`: Rendered toolbar custom element.

### scriptTag() <span id="method-scriptTag"></span>

```php
public function scriptTag(): string
```

Renders a script tag for the Yii2-published toolbar runtime.

Emits `type="module"` so the ES-module chunk keeps its own top-level scope and cannot collide with host-page
globals or other classic scripts.

**Returns**

`string`: Toolbar runtime script tag.