{"id":13540821,"url":"https://github.com/jonassiewertsen/statamic-livewire","last_synced_at":"2025-10-17T15:30:52.430Z","repository":{"id":43111289,"uuid":"266869591","full_name":"jonassiewertsen/statamic-livewire","owner":"jonassiewertsen","description":"A Laravel Livewire integration for Statamics antlers engine","archived":false,"fork":false,"pushed_at":"2024-10-01T13:00:27.000Z","size":123,"stargazers_count":92,"open_issues_count":1,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-26T17:03:13.904Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonassiewertsen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["jonassiewertsen"]}},"created_at":"2020-05-25T20:02:52.000Z","updated_at":"2024-12-10T05:58:07.000Z","dependencies_parsed_at":"2024-06-10T18:32:22.426Z","dependency_job_id":"bb1bb351-c58f-4cba-abfe-a1313fcb426f","html_url":"https://github.com/jonassiewertsen/statamic-livewire","commit_stats":{"total_commits":45,"total_committers":9,"mean_commits":5.0,"dds":0.5555555555555556,"last_synced_commit":"eaf7154b08e3edc0c6aa2451c7da77165e0aae1b"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonassiewertsen%2Fstatamic-livewire","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonassiewertsen%2Fstatamic-livewire/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonassiewertsen%2Fstatamic-livewire/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonassiewertsen%2Fstatamic-livewire/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonassiewertsen","download_url":"https://codeload.github.com/jonassiewertsen/statamic-livewire/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236824719,"owners_count":19210675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T10:00:33.372Z","updated_at":"2025-10-17T15:30:47.096Z","avatar_url":"https://github.com/jonassiewertsen.png","language":"PHP","funding_links":["https://github.com/sponsors/jonassiewertsen","https://github.com/sponsors/jonassiewertsen/"],"categories":["Packages / Plugins"],"sub_categories":[],"readme":"# Statamic Livewire\n\u003c!-- statamic:hide --\u003e\n![Statamic 4.0+](https://img.shields.io/badge/Statamic-4.0+-FF269E?style=for-the-badge\u0026link=https://statamic.com)\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/jonassiewertsen/statamic-livewire.svg?style=for-the-badge)](https://packagist.org/packages/jonassiewertsen/statamic-livewire)\n\u003c!-- /statamic:hide --\u003e\n\n## New Maintainer \nPlease switch to [https://github.com/marcorieser/statamic-livewire](https://github.com/marcorieser/statamic-livewire) instead. Switching is easy and there is no breaking change. Please check the Guide in the new repo.\n\nThanks for your support ❤️\n\n## Description\nA third-party [Laravel Livewire](https://laravel-livewire.com/) integration for Statamic.\n\nIt's as easy as it gets to get started with Livewire if using Statamic.\n\n## Installation\nPull in the Livewire package with composer\n\n```bash\ncomposer require jonassiewertsen/statamic-livewire\n```\n\n### Manually including Livewire's frontend assets\nBy default, Livewire injects the JavaScript and CSS assets it needs into each page that includes a Livewire component. If you want more control over this behavior, you can [manually include the assets](https://livewire.laravel.com/docs/installation#manually-including-livewires-frontend-assets) on a page using the following Antlers tags or Blade directives:\n\n```html\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003c!-- If using Antlers --\u003e\n        {{ livewire:styles }}\n\n        \u003c!-- If using Blade --\u003e\n        @livewireStyles\n    \u003c/head\u003e\n    \u003cbody\u003e\n\n        ...\n        \u003c!-- If using Antlers --\u003e\n        {{ livewire:scripts }}\n\n        \u003c!-- Blade --\u003e\n        @livewireScripts\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Manually bundling Livewire and Alpine\nIf you need to include some custom Alpine plugins, you need to [manually bundle the Livewire and Alpine assets](https://livewire.laravel.com/docs/installation#manually-bundling-livewire-and-alpine) and disable the automatic injection by using the following Antlers tag or Blade directive. Do not forget to include the Livewire styles as well.\n\n```html\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003c!-- If using Antlers --\u003e\n        {{ livewire:styles }}\n\n        \u003c!-- If using Blade --\u003e\n        @livewireStyles\n    \u003c/head\u003e\n    \u003cbody\u003e\n\n        ...\n        \u003c!-- If using Antlers --\u003e\n        {{ livewire:scriptConfig }}\n\n        \u003c!-- Blade --\u003e\n        @livewireScriptConfig\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Static caching\nThis addon adds an `AssetsReplacer` class to make Livewire compatible with half and full static caching. You may customize the replacers in the config of this addon:\n\n```php\n'replacers' =\u003e [\n    \\Jonassiewertsen\\Livewire\\Replacers\\AssetsReplacer::class,\n],\n```\n\nIf you are using full measure static caching and you're manually bundling Livewire and Alpine as per the instructions above, you need to make sure to only start Livewire once the CSRF token has been replaced.\n\n```js\nif (window.livewireScriptConfig?.csrf === 'STATAMIC_CSRF_TOKEN') {\n    document.addEventListener('statamic:nocache.replaced', () =\u003e Livewire.start());\n} else {\n    Livewire.start();\n}\n```\n\n## Upgrade\n\nMake sure to read the Livewire upgrade guide, in case you're updating to `Statamic Livewire` 3, as there are breaking changes:\nhttps://livewire.laravel.com/docs/upgrading\n\n## General documentation\n[Livewire Docs](https://livewire.laravel.com/docs/quickstart)\n\n### Include components\nYou can create Livewire components as described in the [general documentation](https://livewire.laravel.com/docs/components).\nTo include your Livewire component:\n```html\n\u003cbody\u003e\n    \u003c!-- If using Antlers --\u003e\n    {{ livewire:your-component-name }}\n\n    \u003c!-- If using Blade --\u003e\n    \u003clivewire:your-component-name /\u003e\n\u003c/body\u003e\n```\n\nif you want to include a component from a dynamic variable you can use the `livewire:component` tag:\n\n```html\n\u003cbody\u003e\n    \u003c!-- If using Antlers --\u003e\n    {{ livewire:component :name=\"variable\" }}\n\n    \u003c!-- If using Blade --\u003e\n    \u003clivewire:component name=\"$variable\" /\u003e\n\u003c/body\u003e\n```\n\n### @script and @assets\nAntlers versions of [@script](https://livewire.laravel.com/docs/javascript#executing-scripts) and [@assets](https://livewire.laravel.com/docs/javascript#loading-assets) are provided:\n\n```html\n\u003cbody\u003e\n    {{ livewire:script }}\n\t\u003cscript\u003econsole.log('hello')\u003c/script\u003e\n    {{ /livewire:script }}\n\u003c/body\u003e\n```\n\n```html\n\u003cbody\u003e\n    {{ livewire:assets }}\n\t\u003cscript src=\"some-javascript-library.js\"\u003e\u003c/script\u003e\n    {{ /livewire:assets }}\n\u003c/body\u003e\n```\n\n### Blade or Antlers? Both!\nIf creating a Livewire component, you need to render a template file\n\n```php\nnamespace App\\Http\\Livewire;\n\nuse Livewire\\Component;\n\nclass Counter extends Component\n{\n    public function render()\n    {\n        return view('livewire.counter');\n    }\n}\n```\nMore Information: (https://livewire.laravel.com/docs/components)\n\nNormally your template file would be a blade file, named `counter.blade.php`. Great, but what about Antlers?\nRename your template to `counter.antlers.html`, use Antlers syntax and do whatever you like. **No need to change** anything inside your component Controller. How cool is that?\n\n### Passing Initial Parameters\nYou can pass data into a component by passing additional parameters\n```html\n\u003c!-- If using Antlers --\u003e\n{{ livewire:your-component-name :contact=\"contact\" }}\n\n\u003c!-- If using Blade --\u003e\n\u003clivewire:your-component-name :contact=\"$contact\"\u003e\n```\n\nTo intercept with those parameters, mount them and store the data as public properties.\n\n```php\nuse Livewire\\Component;\n\nclass ShowContact extends Component\n{\n    public $name;\n    public $email;\n\n    public function mount($contact)\n    {\n        $this-\u003ename = $contact-\u003ename;\n        $this-\u003eemail = $contact-\u003eemail;\n    }\n\n    ...\n}\n```\n\nThe [Official Livewire documentation](https://livewire.laravel.com/docs/components#rendering-components) provides more information.\n\n### Keying Components\nLivewire components are automatically keyed by default. If you want to manually key a component, you can use the `key` attribute.\n```html\n\u003c!-- If using Antlers --\u003e\n{{ contacts }}\n    {{ livewire:your-component-name :key=\"id\" }}\n{{ /contacts }}\n\n\u003c!-- If using Blade --\u003e\n@foreach ($contacts as $contact)\n    \u003clivewire:your-component-name :key=\"$contact-\u003eid\" /\u003e\n@endforeach\n```\nThe [Official Livewire documentation](https://livewire.laravel.com/docs/components#adding-wirekey-to-foreach-loops) provides more information.\n\n### Multi-Site\nWhen using Livewire in a Multi-Site context, the current site gets lost between requests. There is a trait (`\\Jonassiewertsen\\Livewire\\RestoreCurrentSite`) to solve that. Just include it in your component and use `Site::current()` as you normally do.\n```php\nclass ShowArticles extends Component\n{\n    use \\Jonassiewertsen\\Livewire\\RestoreCurrentSite;\n\n    protected function entries()\n    {\n        return Entry::query()\n            -\u003ewhere('collection', 'articles')\n            -\u003ewhere('site', Site::current())\n            -\u003eget();\n    }\n\n    public function render()\n    {\n        return view('livewire.blog-entries', $this-\u003eentries());\n    }\n}\n```\n\n### Paginating Data\nYou can paginate results by using the WithPagination trait.\n\n#### Blade\nTo use pagination with Blade, please use the `Livewire\\WithPagination` namespace for your trait as described in the [Livewire docs](https://livewire.laravel.com/docs/pagination#basic-usage).\n\n### Antlers\nPagination with Antlers does work similar. Make sure to use the `Jonassiewertsen\\Livewire\\WithPagination` namespace for your trait if working with Antlers.\n\nIn your Livewire component view:\n```html\n{{ entries }}\n    ...\n{{ /entries }}\n\n{{ links }}\n```\n\n```php\nuse Jonassiewertsen\\Livewire\\WithPagination;\n\nclass ShowArticles extends Component\n{\n    use WithPagination;\n\n    protected function entries()\n    {\n        $entries = Entry::query()\n            -\u003ewhere('collection', 'articles')\n            -\u003epaginate(3);\n\n        return $this-\u003ewithPagination('entries', $entries);\n    }\n\n    public function render()\n    {\n        return view('livewire.blog-entries', $this-\u003eentries());\n    }\n}\n```\n\n### EXPERIMENTAL: Statamic Support\nAs a little experiment, support for an Entry or EntryCollection has been added, so you can make an entry or a entry collection simply a public property and it just works.\n\nSupported types:\n- Statamic\\Entries\\EntryCollection;\n- Statamic\\Entries\\Entry;\n\n```php\nnamespace App\\Livewire;\n\nuse Livewire\\Component;\nuse Statamic\\Entries\\EntryCollection;\nuse Statamic\\Entries\\Entry;\n\nclass Foo extends Component\n{\n    public EntryCollection $entries;\n    public Entry $entry;\n\n    // normal livewire stuff\n}\n```\n\nTo make it work, you need to enable that feature first.\n\n1. php artisan vendor:publish\n2. Select statamic-livewire in the list\n3. Enable synthesizers\n\n### Entangle: Sharing State Between Livewire And Alpine\nIn case you want to share state between Livewire and Alpine, there is a Blade directive called `@entangle`. To be usable with Antlers, we do provide a dedicated tag:\n```html\n\u003c!-- With Antlers --\u003e\n\u003cdiv x-data=\"{ open: {{ livewire:entangle property='showDropdown' modifier='live' }} }\"\u003e\n\n\u003c!-- With Blade --\u003e\n\u003cdiv x-data=\"{ open: @entangle('showDropdown').live }\"\u003e\n```\n\nIt's worth mentioning that, since Livewire v3 now builds on top of Alpine, the `@entangle` directive is not documented anymore. Instead, it's possible to entangle the data via [the `$wire` object](https://livewire.laravel.com/docs/javascript#the-wire-object).\n```html\n\u003cdiv x-data=\"{ open: $wire.entangle('showDropdown', true) }\"\u003e\n```\n### This: Accessing the Livewire component\nYou can access and perform actions on the Livewire component like this:\n\n```html\n\u003cscript\u003e\n    document.addEventListener('livewire:initialized', function () {\n        // With Antlers\n        {{ livewire:this set=\"('name', 'Jack')\" }}\n\n        // With Blade\n        @this.set('name', 'Jack')\n    })\n\u003c/script\u003e\n```\nIt's worth mentioning that, since Livewire v3 now builds on top of Alpine, the `@this` directive is not used widely anymore. Instead, it's possible to [access and manipulate the state directly via JavaScript](https://livewire.laravel.com/docs/properties#accessing-properties-from-javascript) / [the `$wire` object](https://livewire.laravel.com/docs/javascript#the-wire-object).\n```html\n\u003cscript\u003e\n    document.addEventListener('livewire:initialized', function () {\n        // `{{ livewire:this }}` returns the instance of the current component\n        {{ livewire:this }}.set('name', 'Jack')\n    })\n\u003c/script\u003e\n```\n### Lazy Components\nLivewire allows you to [lazy load components](https://livewire.laravel.com/docs/lazy) that would otherwise slow down the initial page load. For this you can simply pass `lazy=\"true\"` as argument to your component tag.\n\n```html\n\u003c!-- With Antlers --\u003e\n{{ livewire:your-component-name :contact=\"contact\" lazy=\"true\" }}\n```\n\n## Other Statamic Livewire Packages\nIf using Livewire, those packages might be interesting for you as well:\n- [Statamic live search](https://github.com/jonassiewertsen/statamic-live-search)\n- [Statamic Livewire Forms](https://github.com/aerni/statamic-livewire-forms)\n- [Antlers Components](https://github.com/Stillat/antlers-components)\n\nDid I miss a link? Let me know!\n\n## Credits\n\nThanks to:\n- [Marco Rieser](https://github.com/marcorieser) to help maintaining this package\n- [Caleb](https://github.com/calebporzio) and the community for building [Livewire](https://laravel-livewire.com/)\n- [Austenc](https://github.com/austenc) for the Statamic marketplace preview image\n\n## Requirements\n- PHP 8.1\n- Laravel 10 or 11\n- Statamic 4 or 5\n\n# Support\nI love to share with the community. Nevertheless, it does take a lot of work, time and effort.\n\n[Sponsor me on GitHub](https://github.com/sponsors/jonassiewertsen/) to support my work and the support for this addon.\n\n# License\nThis plugin is published under the MIT license. Feel free to use it and remember to spread love.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonassiewertsen%2Fstatamic-livewire","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonassiewertsen%2Fstatamic-livewire","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonassiewertsen%2Fstatamic-livewire/lists"}