Getting Started
Install
Deno
With Deno, just import Vento like so:
import vento from "https://deno.land/x/vento@v0.9.1/mod.ts";
Node.js
In Node.js, install it from NPM:
npm install ventojs
And then import Vento:
import vento from "ventojs";
Usage
First, create an instance of Vento.
const env = vento();
load
You can use load
to load and compile a template from a path. The compiled
templates are stored in an internal cache, so they are only compiled once.
const template = await env.load("my-template.vto");
const result = await template({ title: "Hello, world!" });
run
Alternatively, you can load and run the template file in a single call:
const result = await env.run("my-template.vto", { title: "Hello, world!" });
runString
If the template code is not a file, you can run it directly:
const result = await env.runString("<h1>{{ title }}</h1>", {
title: "Hello, world!",
});
console.log(result.content);
// <h1>Hello, world!</h1>
Clearing cache
Vento implements a cache to prevent excessive compilation. If you need to reload your templates at runtime (ie. for development), you can clear the cache.
env.cache.clear();