PHPackages                             sroze/live-twig - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. sroze/live-twig

ActiveLibrary[Templating &amp; Views](/categories/templating)

sroze/live-twig
===============

3413PHPCI failing

Since Oct 5Pushed 5y ago1 watchersCompare

[ Source](https://github.com/sroze/live-twig)[ Packagist](https://packagist.org/packages/sroze/live-twig)[ RSS](/packages/sroze-live-twig/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

LiveTwig
========

[](#livetwig)

Let's get rid of the SPAs! Here's how to get real-time Twig blocks basically. Bisous. 😘

Setup
-----

[](#setup)

1. Install the dependency

    composer req sroze/live-twig
2. Get Mercure Hub running. You can have a look to [the Mercure documentation](https://mercure.rocks/docs/hub/install). Simplest is with Docker:

    docker run --rm -e CORS\_ALLOWED\_ORIGINS='' -e JWT\_KEY='!ChangeMe!' -e DEMO=1 -e ALLOW\_ANONYMOUS=1 -e PUBLISH\_ALLOWED\_ORIGINS='' -p 80:80 dunglas/mercure
3. Get your Mercure JWT token. If you are using the default demo `JWT_KEY`, you can get the token from [your running hub's homepage.](http://localhost/).
4. Set environment variables

    .env
    ====

    [](#env)

    ...
    ===

    [](#)

    MERCURE\_PUBLISH\_URL=MERCURE\_JWT\_TOKEN=\[your-token\]
5. (While the Flex recipe is not done) Regisyer the bundle:

    ```
    // config/bundles.php
    return [
        // ...
        Symfony\Bundle\LiveTwigBundle\LiveTwigBundle::class => ['all' => true],
    ];
    ```

    Create the following configuration file:

    ```
    # config/packages/live_twig.yaml
    live_twig:
        mercure_public_url: "%env(MERCURE_PUBLISH_URL)%"
    ```

Use it!
-------

[](#use-it)

Anywhere in your Twig templates, render a live block:

```
{{
    render_live(
        controller('App\\Controller\\YourController::yourAction', { some: 'parameter' }),
        {'topics': ['foo', 'bar-' ~ baz]}
    )
}}
```

When the data contained in this block change, publish an empty Mercure update:

```
