Download the PHP package becklyn/javascript-context without Composer
On this page you can find all versions of the php package becklyn/javascript-context. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download becklyn/javascript-context
More information about becklyn/javascript-context
Files in becklyn/javascript-context
Package javascript-context
Short Description A way to send data from PHP to JavaScript.
License BSD-3-Clause
Homepage https://github.com/Becklyn/JavaScriptContext
Informations about the package javascript-context
JavaScript Context
A simple library to send data from PHP to JavaScript.
Usage
Fetch the JavaScriptContext
service:
Afterwards embed it in your twig template:
The container will have the _javascript-context _data-container
classes and the ID _javascript-context
.
To modify the ID, pass the new ID to the function:
Fetching the Data
To fetch the data from the script
container, just JSON-parse it, after removing the HTML escaping, for example:
In the JSON output, only the following chars are HTML escaped: <
, >
and &
.
Context Providers
If some data has to always be passed to the template, then it is convenient to just register a context provider.
Each provider receives the context to modify, as well as optionally a domain. This is just a string
key with which
the providers can decide whether they want to attach data or not.
For example to separate the context into app
and backend
you can just register all providers and then in your
template include it like this:
You must add the tag javascript_context.provider
to your service.
If you use autoconfiguration, the tag is added automatically.
All versions of javascript-context with dependencies
ext-json Version *
symfony/config Version ^4.3 || ^5.0
symfony/dependency-injection Version ^4.3 || ^5.0
symfony/http-kernel Version ^4.3 || ^5.0
symfony/phpunit-bridge Version ^5.0
twig/twig Version ^2.11 || ^3.0