Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
maxLevel3
minLevel2

Anchor
anc-defining-and-referencing
anc-defining-and-referencing
Defining, referencing and using a JavaScript model

Anchor
base-recipe
base-recipe

...


Code Pro
your-light-module/
└── templates
    └── pages
        ├── rhino.ftl
        ├── rhino.js
        └── rhino.yaml

This recipe works for both page and component templates.

Using the modelPath and class property

...

With this approach you do not have to follow the naming convention

...

. This can be handy

...

to use the same model

...

among multiple templates.

...

Instead of the property modelClass, you must set the properties class and modelPath. The value for the former must be info.magnolia.module.jsmodels.rendering.JavascriptTemplateDefinition and for the latter the path to the JavaScript model.

Example:

Code Pro
languageyaml
titlerhino.yaml
templateScript: /your-light-module/templates/pages/rhino.ftl
renderType: freemarker

...

class: info.magnolia.module.jsmodels.rendering.

...

JavascriptTemplateDefinition
modelPath: /your-light-module/templates/common/baseModel.js

Nashorn, JavaScript and the Java API

...