Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bigoen/mercure-twig-bundle

Mercure Twig Bundle
https://github.com/bigoen/mercure-twig-bundle

mercure symfony symfony-bundle symfony-flex twig

Last synced: 2 days ago
JSON representation

Mercure Twig Bundle

Awesome Lists containing this project

README

        

Mercure Twig Bundle
=
Developed based on https://github.com/sroze/live-twig package.

**Install:**
```
composer require bigoen/mercure-twig-bundle
```

**If you don't use Symfony Flex:**

.env.local
```dotenv
###> bigoen/mercure-twig-bundle ###
MERCURE_TWIG_PUBLISH_URL=http://mercure/.well-known/mercure
###< bigoen/mercure-twig-bundle ###
```

config/bundles.php
```php
return [
// ...
Bigoen\MercureTwigBundle\BigoenMercureTwigBundle::class => ['all' => true],
];
```

config/packages/bigoen_mercure_twig.yaml
```yaml
bigoen_mercure_twig:
public_url: "%env(MERCURE_TWIG_PUBLISH_URL)%"
# subscriber_js: '@BigoenMercureTwig\subscriber_js.html.twig'
```

How to use?
-
**Configurations:**
- Set MERCURE_TWIG_PUBLISH_URL,
- Set subscriber_js in yaml configuration. Default: '@BigoenMercureTwig\subscriber_js.html.twig'

**Publisher Example:**
```php
use Symfony\Component\Mercure\PublisherInterface;
use Symfony\Component\Mercure\Update;

/** @var PublisherInterface $publisher */
$publisher(new Update('live', 'test'));
```

**Controller Example:**
```php
render('mercure/order.html.twig');
}
}
```

**Twig Example:**
- Set render controller,
- Set mercure topics,
- Set token is private.
- Set isAdd. Default: 0. 1 = afterbegin, 2 = beforebegin.
```twig
{{ render_bigoen_mercure_twig(
controller('App\\Controller\\MercureController::orderAction'),
{'topics': ['live'], 'isAdd': 1, 'token': 'bearer token'}
) }}
```