avris / micrus-js
JavaScript plugin for Micrus framework (handles routing and localization)
Requires
- avris/micrus: ^3.0
- avris/micrus-localizator: ^3.0
- avris/micrus-twig: ^3.0
Requires (Dev)
- symfony/process: ^3.2
This package is auto-updated.
Last update: 2020-02-05 22:57:15 UTC
README
This is a module for Micrus framework that allows you to generate asset URLs, route URLs and localized strings from client-side JavaScript code.
To install this module, open the file app/Config/modules.yml
and add:
- Avris\Micrus\MicrusJs\MicrusJsModule
Then run:
composer require avris/micrus-js
Then add this code to your main layout:
<script src="{{ route('micrusjs') }}"></script>
Sample
Available methods correspond to their PHP version.
console.log(M.user);
console.log(M.isGranted('ROLE_ADMIN'));
console.log(M.routeExists('routeName'));
console.log(M.route('routeName', {id: 15}));
console.log(M.locale);
console.log(M.l('localized.string', {foo: "bar"}));
console.log(M.asset('image.png'));
Extending
If you want to pass some dynamic data to JavaScript, say, the name of a current route,
you can do it by defining a service with tag jsVars
that implements Avris\Micrus\MicrusJs\JsVarsInterface
:
To define a JS version of a localizator selector (see: Localizator Module)
make it implement Avris\Micrus\MicrusJs\JsFunctionInterface
.
Copyright
- Author: Andrzej Prusinowski (Avris.it)
- Licence: MIT