Giter VIP home page Giter VIP logo

mercure-twig-bundle's Introduction

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

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

config/bundles.php

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

config/packages/bigoen_mercure_twig.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:

use Symfony\Component\Mercure\PublisherInterface;
use Symfony\Component\Mercure\Update;

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

Controller Example:

<?php

declare(strict_types=1);

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
 * @Route("/mercure", name="mercure.")
 */
class MercureController extends AbstractController
{
    /**
     * @Route("/order", name="order")
     */
    public function orderAction(): Response
    {
        return $this->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.
{{ render_bigoen_mercure_twig(
    controller('App\\Controller\\MercureController::orderAction'),
    {'topics': ['live'], 'isAdd': 1, 'token': 'bearer token'}
) }}

mercure-twig-bundle's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.