-
Notifications
You must be signed in to change notification settings - Fork 0
Render
To render a file, simply use the render
function. If the file is not present in the cache, it will be compiled and added to the cache.
eryn.render("/path/to/file.eryn", {...});
It is recommended to pass the absolute path to the file, for the reasons specified here.
eryn.render(path.join(__dirname, "file.eryn"), {...});
The first argument is the file path, the second argument is the context
object (more info here), and the third argument is the optional shared
object (more info here). The shared object doesn't appear on this page in order to simplify things.
If you don't pass anything for the second argument, it will default to {}
.
The render
function returns a Buffer
containing the rendered data. It returns a buffer instead of a string because the compiler and renderer were purposely designed to work with raw binary data. This means that eryn can be also be used with binary files (or any type of files, really), so the engine is not limited to just server-side rendering.
You can render a string like this:
eryn.renderString("alias", {...});
Please note that the string must first be compiled with the compileString
function. It's not possible to directly render a string without first compiling it.
eryn.compileString("testAlias", "Here's the context: [| context |]");
var data = eryn.renderString("testAlias", { test: "value" });
You can render a temporary string like this:
eryn.renderStringUncached("src", {...});
This compiles the given template and renders it with the given context. You can use this function to render one-time strings.