Imports and exports
Exporting
Use template.exports
object, to expose variables or functions to your template.
```pochoir-js
template.exports.who = "John Doe";
```
I am {{who}}.
Output:
I am John Doe.
You can even export a function use it in properties
---
author: "{{fullname()}}"
---
```pochoir-js
template.exports.fullname = () => {
return "John Doe";
};
```
Article created by {{fullname()}}.
Output:
---
author: "John Doe"
---
Article created by John Doe.
Importing
template.exports
is also useful combined with template.import()
to share code between template:
Here a template [[Functions]]
:
```pochoir-js
const age = 34;
template.exports.fakeAge = () => {
return age - 4;
};
```
and another template:
```pochoir-js
const { fakeAge } = await template.import("[[Functions]]");
template.exports.age = fakeAge;
```
I am {{age()}} years old.
Output:
I am 30 years old.