Skip to content

API for scripts

Daniel Stirba edited this page Oct 6, 2026 · 1 revision

API for scripts

Templater, QuickAdd, Dataview JS or any plugin that runs JavaScript can use the generators.

const fcg = app.plugins.plugins["fantasy-content-generator"].api;

The id stays fantasy-content-generator after the rename to TTRPG Content Generator.

generate(key, values?)

One result as text. key is any key that works with @ (built-in or your own).

fcg.generate("InnsTaverns");
fcg.generate("Tavern", { wealth: 70, race: "Dwarf" });

values are passed in exactly like {@Tavern $wealth=70 $race=Dwarf}: the generator starts with them (see ?= in Pattern reference). Built-in generators ignore them.

In a Templater template:

<% app.plugins.plugins["fantasy-content-generator"].api.generate("Dwarvish") %>

generateData(key, values?)

The result and everything the generator remembered, including the values you passed in:

const village = fcg.generateData("ExampleVillage");
// {
//   text: "# Village C\nA … village, mostly Dwarf folk (wealth 45).\n…",
//   values: { wealth: 45, race: "Dwarf", name: "Village C" }
// }

Use the values to name notes, make folders, link notes and pass them on to the next generator. Build a village is a full example.

  • Value names are written without $ ($wealth → wealth). You can pass them with or without it.
  • Numbers stay numbers, text stays text; true/false become 1/0.

keys()

Every key that works with @: built-in first, then yours.

Errors

Both functions throw an Error with a readable message for an unknown key or a generator with a problem, so wrap calls in try/catch if a script should carry on.

Clone this wiki locally