Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions content/collections/pages/building-a-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,51 @@ You may choose to create aliases for your tag too. It will then be usable by its
protected static $aliases = ['sample'];
```

## Namespaced Tags

Tags can be registered under a namespace to avoid handle collisions between addons. Without namespacing, if two addons register a tag with the same handle, the last one registered wins.

### Enabling namespacing in an addon

Set the `$tagNamespace` property on your addon's service provider. All tags registered by that addon will be callable under that namespace.

```php
class ServiceProvider extends AddonServiceProvider
{
protected $tagNamespace = 'my-addon';
}
```

::tabs

::tab antlers
```antlers
{{ my-addon::my_tag:method }}
```
::tab blade
```blade
<s:my-addon::my_tag:method />
```
::

When using the [fluent tag syntax](/blade#using-fluent-tags-with-blade), include the namespace:

```php
Statamic::tag('my-addon::my_tag:method')->fetch();
```

### Manual registration with a namespace

You can also register a single tag class under a namespace directly:

```php
MyTag::register('my-addon');
```

:::tip
Namespacing is opt-in. Addons without `$tagNamespace` continue to work exactly as before. Tags can still be called without the namespace if there is no collision.
:::

## Parameters

You may get the values of parameters through the `parameters` property.
Expand Down
9 changes: 9 additions & 0 deletions content/collections/pages/building-an-addon.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ protected $commands = [
];
```

To avoid tag handle collisions with other addons, you can register all your tags under a namespace by setting `$tagNamespace` on your service provider:

``` php
protected $tagNamespace = 'my-addon';
```

Tags will then be callable as `{{ my-addon::tag_name }}`. See [Namespaced Tags](/building-a-tag#namespaced-tags) for full details.


## Assets

### CSS and Javascript
Expand Down