File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ Subscribing to updates in JavaScript from a Twig template is straightforward:
251
251
// Will be called every time an update is published by the server
252
252
console.log(JSON.parse(event.data));
253
253
}
254
- <script>
254
+ </ script>
255
255
256
256
The ``mercure() `` Twig function will generate the URL of the Mercure hub
257
257
according to the configuration. The URL will include the ``topic `` query
@@ -260,13 +260,15 @@ parameters corresponding to the topics passed as first argument.
260
260
If you want to access to this URL from an external JavaScript file, generate the
261
261
URL in a dedicated HTML element:
262
262
263
- .. code :: twig
263
+ .. code-block :: twig
264
264
265
- <script type="application/json" id="mercure-url">{{ mercure('https://example.com/books/1')|json_encode(constant('JSON_UNESCAPED_SLASHES') b-or constant('JSON_HEX_TAG'))|raw }}</script>
265
+ <script type="application/json" id="mercure-url">
266
+ {{ mercure('https://example.com/books/1')|json_encode(constant('JSON_UNESCAPED_SLASHES') b-or constant('JSON_HEX_TAG'))|raw }}
267
+ </script>
266
268
267
269
Then retrieve it from your JS file:
268
270
269
- .. code :: javascript
271
+ .. code-block :: javascript
270
272
271
273
const url = JSON .parse (document .getElementById (" mercure-url" ).textContent );
272
274
const eventSource = new EventSource (url);
You can’t perform that action at this time.
0 commit comments