avris/micrus-js

This package is abandoned and no longer maintained. No replacement package was suggested.

JavaScript plugin for Micrus framework (handles routing and localization)

v3.0.1 2017-06-27 10:28 UTC

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