8000 GitHub - bjornbjorn/livewire-twig: Add Livewire components in your Twig templates
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Livewire components in your Twig templates

License

Notifications You must be signed in to change notification settings

bjornbjorn/livewire-twig

 
 

Repository files navigation

Livewire for Twig

Latest Version on Packagist GitHub Workflow Status Total Downloads

The enflow/livewire-twig package provides the option to load Livewire components in your Twig templates.

Installation

You can install the package via composer:

composer require enflow/livewire-twig

Usage

The Twig extension will automatically register when rcrowe/twigbridge is used. If you're using another configuration, you may wish to register the extension manually by loading the extension Enflow\LivewireTwig\LivewireExtension.

This package only provides a wrapper for the @livewireScripts, @livewireStyles & @livewire calls. Everything else under the hood is powered by livewire/livewire.
You can register your Livewire components like normal.

Installation

Add the following tags in the head tag, and before the end body tag in your template.

<html>
<head>
    ...
    {{ livewireStyles() }}
</head>
<body>
    ...
    {{ livewireScripts() }}
</body>
</html>

In your body you may include the component like:

{# The Twig version of '@livewire' #}
{% livewire counter %}

{# If you wish to pass along variables to your component #}
{% livewire counter with {'count': 3} %}

Example

Add the following to resources/views/livewire/counter.twig

<div>
    <div wire:click="add">+</div>
    <div>{{ count }}</div>
    <div wire:click="subtract">-</div>
</div>

Add the following to app/Http/Livewire/Counter.php

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class Counter extends Component
{
    public int $count = 1;

    public function add()
    {
        $this->count++;
    }

    public function subtract()
    {
        $this->count--;
    }
}

Caveats

  • Components with hyphens cannot be called like {% livewire foo-bar %} as Twig doesn't allow hyphens like that. We've added a workaround for this by allowing camel case: {% livewire fooBar %}

Todo

  • Implement support for key tracking
  • Implement support for preserving child tracking
  • Moar tests.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email michel@enflow.nl instead of using the issue tracker.

Credits

About Enflow

Enflow is a digital creative agency based in Alphen aan den Rijn, Netherlands. We specialize in developing web applications, mobile applications and websites. You can find more info on our website.

License

The MIT License (MIT). Please see License File for more information.

About

Add Livewire components in your Twig templates

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 94.4%
  • Twig 5.6%
0