-
Notifications
You must be signed in to change notification settings - Fork 0
Context
Constantin Mihai edited this page Apr 17, 2021
·
7 revisions
A context
object is an object that contains properties which are used to render a file.
since 0.2.8 The context value can now be of any type. It's no longer required to be an object.
The context is passed to the render
function as the second argument, after the path
.
Here's a basic example:
test.js
erny.render("/path/to/test.eryn", { firstName: "Tyler", lastName: "Bounty" });
test.eryn
Hello, [| context.firstName |] [| context.lastName |]!
This will be rendered as:
Hello, Tyler Bounty!
You can see that the firstName
and lastName
properties are accessible through the context
object.
The properties are not limited to strings. You can also use types like Object
and Array
:
test.js
eryn.render("/path/to/test.eryn", {
user: {
name: "Tyler",
favoriteNumbers: [2, 21, 46]
}
});
test.eryn
Hello, [| context.user.name |]!
Your second favorite number is [| context.user.favoriteNumbers[1] |].
This will be rendered as:
Hello, Tyler!
Your second favorite number is 21.
For more information on templates, and what you can do with them, read the Templates page.