https://github.com/daun/statamic-embed-fieldtype
Fieldtype for embedding and previewing external content in Statamic
https://github.com/daun/statamic-embed-fieldtype
embed statamic statamic-addon
Last synced: about 1 month ago
JSON representation
Fieldtype for embedding and previewing external content in Statamic
- Host: GitHub
- URL: https://github.com/daun/statamic-embed-fieldtype
- Owner: daun
- License: mit
- Created: 2025-11-30T21:49:03.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-12-05T08:52:04.000Z (4 months ago)
- Last Synced: 2025-12-08T01:53:45.443Z (4 months ago)
- Topics: embed, statamic, statamic-addon
- Language: PHP
- Homepage: https://statamic.com/addons/daun/embed-fieldtype
- Size: 1.62 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Statamic Embed Fieldtype
Fieldtype for embedding and previewing external content.

## Features
- Augment URLs with embed data: iframe, thumbnail, title, description
- Live preview of embedded content in the control panel
- Powered by the [Embed](https://github.com/php-embed/Embed) library and extensible with custom adapters
- Supports any provider with oEmbed endpoint or Open Graph meta tags
## Vs. the Built-In Video Fieldtype
If you need to embed videos from YouTube and Vimeo, you should probably stick with Statamic's
built-in [video fieldtype](https://statamic.dev/fieldtypes/video). It comes with less complexity
as it doesn't need to fetch the metadata or embed codes.
The fieldtype of this addon becomes useful if you need:
- Other providers and content types like audio players, social media posts, etc
- Ready-to-render html for embedding the content in an iframe
- Additional metadata like title, description, thumbnail, etc
## Installation
Install the addon via Composer:
```bash
composer require daun/statamic-embed-fieldtype
```
## Fieldtype
The addon ships with an `embed` fieldtype that accepts a url and shows a preview in the editor.
```yaml
fields:
-
handle: embed
field:
type: embed
display: Embed
```
## Frontend
The fieldtype augments the url to an array of embed data. The following example
will render a simple embed card with either an iframe (if available) or a preview
image.
```html
{{ if embed:url }}
{{ if embed:code }}
{{ elseif embed:image }}
{{ /if }}
{{ if embed:title }}
{{ if embed:description || embed:author:name }}
{{ embed:description ?? embed:author:name }}
{{ /if }}
{{ if embed:provider:url }}
{{ embed:provider:url | replace('https://', '') }}
{{ /if }}
{{ /if }}
{{ /if }}
```
### Unaugmented URL
If you want to use the raw url without augmentation, you can access it via `embed:url`. To turn off
augmentation completely, you can set the field config `augment_to_embed_data` to `false`. This will
return the url as-is in all frontend contexts.
```diff
fields:
-
handle: embed
field:
type: embed
display: Embed
+ augment_to_embed_data: false
```
## Extending the Embed Library
The addon uses the [Embed](https://github.com/php-embed/Embed) library under the hood, which supports
a variety of providers out of the box: YouTube, Vimeo, Instagram, Flickr, etc. You can customize the
library instance and settings and also create custom adapters for unsupported providers by registering
a resolving callback in your service provider. See [Extending Embed](https://github.com/php-embed/Embed?tab=readme-ov-file#extending-embed)
for details and examples.
```php
namespace App\Providers;
use Embed\Embed;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->afterResolving(Embed::class, function (Embed $embed) {
$embed->getExtractorFactory()->addAdapter('mysite.com', MySite::class);
$embed->setSettings([
'instagram:token' => '12345678',
'twitter:token' => 'abcdefgh',
]);
});
}
}
```
## License
[MIT](https://opensource.org/licenses/MIT)