jonassiewertsen/statamic-livewire

A Laravel Livewire integration for Statamics antlers engine.

Fund package maintenance!
jonassiewertsen

Installs: 557

Dependents: 1

Suggesters: 0

Security: 0

Stars: 10

Watchers: 2

Forks: 0

Open Issues: 0

Type:statamic-addon

v1.1.4 2020-09-02 21:38 UTC

This package is auto-updated.

Last update: 2020-09-02 21:40:04 UTC


README

Statamic 3.0+ Latest Version on Packagist

A Laravel Livewire integration for Statamics Antlers template engine.

Installation

Pull in your package with composer

composer require jonassiewertsen/statamic-livewire

General documentation

Laravel Livewire Docs

How to be used with the Antlers template engine

Include the JavaScript (on every page that will be using Livewire).

...
    {{ livewire:styles }}
</head>
<body>

    ...
    {{ livewire:scripts }}
</body>
</html>

Include components with Antlers

You can create Livewire components as described in the general documentation. To include your Livewire component:

<head>
    ...
    {{ livewire:styles }}
</head>
<body>
    {{ livewire:your-component-name }}

    ...

    {{ livewire:scripts }}
</body>
</html>

Blade or Antlers? Both!

If creating a Livewire component, you need to render a template file

namespace App\Http\Livewire;

use Livewire\Component;

class Counter extends Component
{
    public function render()
    {
        return view('livewire.counter');
    }
}

More Information: (https://laravel-livewire.com/docs/quickstart#create-a-component)

Normally your template file would be a blade file, named counter.blade.php. Great, but what about Antlers? Rename your template to counter.antlers.html, use Antlers syntax and do wathever you like. No need to change anything inside your component Controller. How cool is that?

Passing Initial Parameters

You can pass data into a component by passing additional parameters

{{ livewire:your-component-name contact="contact" }}

To intercept with those parameters, mount them and store the data as public properties.

use Livewire\Component;

class ShowContact extends Component
{
    public $name;
    public $email;

    public function mount($contact)
    {
        $this->name = $contact->name;
        $this->email = $contact->email;
    }

    ...
}

The Official Livewire documentation

Requirements

  • PHP 7.4
  • Laravel 7
  • Statamic 3

Support

I love to share with the community. Nevertheless, it does take a lot of work, time and effort.

Sponsor me on GitHub to support my work and the support for this addon.

License

This plugin is published under the MIT license. Feel free to use it and remember to spread love.