Skip to content
Constantin Mihai edited this page Jun 16, 2022 · 14 revisions

eryn

Engine Modes since 0.3.0

Eryn comes with 2 built-in bridges for communicating with Node.js:

  • the normal bridge (flexible): allows the templates to contain any valid JavaScript code
  • the strict bridge (fast): only allows direct variable references

To change the mode under which the engine operates, simply do this:

eryn.setOptions({
    mode: 'strict' // default: 'normal'
});

Normal

In normal mode, the engine functions normally. The templates page reflects the behavior of the system under these circumstances. This mode is flexible due to the fact that it allows any valid JavaScript code in the templates.

Strict

Strict mode is similar, but the engine limits the contents of the templates. Strict mode is faster because it communicates more efficiently with Node.js: instead of using the eval function, it uses functions from N-API. This is the reason why it's much more limited. However, if speed is a concern, this mode should be used if possible.

In strict mode, the following can no longer contain any JavaScript code, and must instead only contain direct variable references:

  • normal and void templates
  • all conditional templates
  • the object/array in loop templates
  • the context in component templates

Direct variable reference means a maximum field depth of 1.

These are ok:

[|context.post|]
[|context["post"]|]

These aren't:

[|context.post.title|]
[|context["post"]["title"]|]

Beware that loop iterators are actually stored in the local object (see the local object page for more info). Therefore:

This is ok:

[|@ iterator : context.items |]
    [|iterator|]
[|end|]

(aka [|local["iterator"]|])

This isn't:

[|@ iterator : context.items |]
    [|iterator.field|]
[|end|]

(aka [|local["iterator"].field|])

Also, every reference must start with either context, local, or shared. The only exceptions are the local iterator (again, this is because they are actually prefixed by local), and the special template [|content|] used by components.

Example

The following table shows multiple examples which may or may not be accepted in strict mode.

Template Normal mode Strict mode
[|content|]
[|context.name|]
[|context.name.stuff|]
[|context.name.substring(2)|]
[|context.surname + context.name|]
[|iterator|]
[|iterator.field|]

Intro

    Home

    Getting Started

Engine Basics

    Context

    Templates

    Local

    Shared

    Modes

Functions

    Compile

    Render

    Options

Other

    Security Concerns

    Known Issues

Clone this wiki locally