Plugins
Package and WebAssembly plugins
Static plugins with templates, blocks and settings (no server-side code), and plugins with Go code compiled to WebAssembly or run as a separate service
On this page
Besides JavaScript plugins there are two more kinds:
| Kind | Good for | Server-side code |
|---|---|---|
| Package (static) | Designer blocks, banners, page scripts, webhooks | None — the fastest review |
| Service (WASM / separate) | Work that needs another language (e.g. Go) or its own container | WebAssembly in the CMS's sandbox, or a separate program |
Package plugins#
hello-banner/
├── manifest.json
├── README.md
├── assets/banner.css → <link rel="stylesheet"> on every page
├── assets/banner.js → <script defer> on every page
└── templates/
├── body.html → inserted before </body>
├── card.html → the block's template
└── card.css → the block's CSS (scoped automatically)
{
"id": "hello-banner",
"name": "Hello Banner",
"version": "1.0.0",
"icon": "📣",
"category": "marketing",
"minCore": "2.0.0",
"permissions": ["head", "bodyEnd", "blocks", "settings"],
"settings": [
{ "key": "text", "type": "text", "label": { "th": "ข้อความ", "en": "Text" }, "default": "Hello" },
{ "key": "background", "type": "color", "label": { "th": "สีพื้นหลัง", "en": "Background" }, "default": "#4f46e5" }
],
"head": ["assets/banner.css", "assets/banner.js"],
"bodyEnd": "templates/body.html",
"blocks": [{
"type": "card",
"name": { "th": "การ์ด", "en": "Card" },
"icon": "🧩",
"template": "templates/card.html",
"css": "templates/card.css",
"props": [{ "key": "title", "type": "text", "label": "Title", "default": "Hi" }]
}]
}
<!-- templates/body.html — every value is HTML-escaped automatically -->
<div class="hb" style="--hb-bg: {{settings.background}}">{{settings.text}}</div>
- Placeholders:
{{settings.key}},{{props.key}}(blocks),{{site.title}},{{post.title}},{{item.key}}(inside a collection) — no loops or conditions - Never put placeholders inside
<script>or<style>— pass data to JS throughdata-*instead - Setting types:
text,textarea,number,color,boolean,select,url,image - Block CSS is scoped under
.pb-<plugin>-<type>(use:scopeor&for the wrapper) - Webhooks:
"webhooks": [{ "event": "post.published", "url": "{{settings.webhookUrl}}" }]— system eventspost.published,user.created,media.uploaded, or other plugins' events such asform.submitted
WebAssembly plugins (a service inside the CMS)#
Put plugin.wasm in the package with a service section — one-click install. The CMS runs it in a sandbox (no files, network or database beyond the APIs it asks for) with 256 MB of memory.
{
"id": "hello-service", "name": "Hello Service", "version": "1.0.0", "icon": "🛰",
"permissions": ["service", "blocks"],
"service": {
"runtime": "wasm",
"module": "plugin.wasm",
"public": ["/hello"],
"api": ["site", "content", "storage"]
}
}
Write it with the Go SDK (sdk/go/anasaki in the repository) and compile to wasip1:
p := anasaki.New(anasaki.Config{Name: "Hello Service", Version: "1.0.0"})
p.Public("GET /hello", func(w http.ResponseWriter, r *http.Request) {
anasaki.Page(w, http.StatusOK, "Hello", "<h1>Hello!</h1>") // shown inside the site's header/footer
})
p.Block("greeting", func(in anasaki.BlockInput) anasaki.BlockOutput { return anasaki.BlockOutput{HTML: "…"} })
log.Fatal(anasaki.Run(p, ":9300"))
GOOS=wasip1 GOARCH=wasm go build -trimpath -ldflags="-s -w" -o package/plugin.wasm .
- API permissions:
site,mail,content,users,events,storage(the plugin's key/value store),http(onlyservice.hosts) - Time: blocks and collections 3 seconds, public pages 30 seconds, admin pages 60 seconds — the module starts fresh for every request, so keep state in storage, not in global variables
- Declare
service.functionsso JavaScript code can call it withplugins.call('<id>', '<fn>', input)
A separate service (its own container)#
The same code builds as a normal program (go build) and runs next to the CMS in docker-compose.yml:
hello-service:
image: example/hello-service:1.0.0
environment:
ANASAKI_PLUGIN_ID: hello-service
ANASAKI_PLUGIN_SECRET: ${HELLO_SERVICE_SECRET}
ANASAKI_URL: http://studio:8090
restart: unless-stopped
The site owner enters the service's address and passes the secret on the plugin's settings page (Installing plugins). The CMS signs every request with HMAC-SHA256 (the SDK checks it), and the service needs no public port.
The full specification (package limits, protocol, v1/v2 signatures, pl_<id>_* cookies) is in docs/plugins.md of the repository. Complete examples: examples/plugins/ and examples/service-plugins/hello-service.
