-
New Feature
-
Resolution: Fixed
-
Neutral
-
None
-
None
-
-
Empty show more show less
-
Kromeriz 125
-
3
Feature
With the introduction of the JavaScript Models module - models can be used in light-modules, the JS syntax makes them well suitable for frontend developers.
The commands create-page and create-component should be able to create a JS model optionally.
Proposed option: -m or -jsm.
Solution
On the template definition add this line:
modelClass: info.magnolia.module.jsmodels.rendering.JavascriptRenderingModel
Create an additional file in the same directory as the template def. and script are created. File name must be <template-name>.js.
Add dummy code to the model file such as this:
/** * Define properties and methods which can be accessed on the template script.<br/> * You can use Magnolia rendering context objects content, def, ctx, state, i18n.<br/> * For further info see https://documentation.magnolia-cms.com/display/DOCS/JavaScript+Models+module.<br/> */ var Foobar = function () { this.getRandomNumber = function () { return Math.random(); } }; new Foobar();
EDIT:
As discussed in the PR, we used prototype with javascript model. The solution above has changed, command for creating a template with js model is following:
mgnl create-<page/component> newPageOrComponent -P with-js-model
Acceptance criteria