Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/bigoen/mercure-twig-bundle
- Owner: bigoen
- License: mit
- Created: 2020-12-10T10:53:17.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-08T14:55:24.000Z (over 3 years ago)
- Last Synced: 2024-05-06T04:01:55.513Z (6 months ago)
- Topics: mercure, symfony, symfony-bundle, symfony-flex, twig
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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'}
) }}
```