Beta documentation. This is an early preview — content is still in active development. Feedback helps shape the final release. Share your thoughts or join the discussion.

api.sites

`api.sites` gives you information about your sites. It's the smallest domain — just 3 functions — but essential for multi-site dashboards and admin panels.

On this page

The site domain

api.sites gives you information about your sites. It's the smallest domain — just 3 functions — but essential for multi-site dashboards and admin panels.

Function reference

Function Returns Description
api.sites.get(id) table or nil Get a site by ID
api.sites.list(page?) { items, total } List all sites
api.sites.current() table Get the current site info

Current site

The most commonly used function — read your site's metadata:

local site = api.sites.current()
print(site.name)    -- "mysite"
print(site.id)      -- 18448
print(site.type)    -- 2 (Lua engine)

Building a site switcher

For users who manage multiple sites:

app:get("/dashboard", function(ctx)
    local sites = api.sites.list()
    local current = api.sites.current()

    return ctx:render("dashboard", {
        sites = sites.items,
        current_site = current,
        site_count = sites.total
    })
end)

Site fields

Each site object includes these fields:

Field Type Description
id number Unique site ID
name string Subdomain name
type number Engine type (1=TAG, 2=Lua, 3=Native App)
owner_id number User ID of the site owner
created_at string Creation timestamp
config table Site configuration

Practical use: site info in layouts

app:on("before", function(ctx)
    ctx.site = api.sites.current()
end)

app:get("/", function(ctx)
    return ctx:render("home", {
        site_name = ctx.site.name,
        site_id = ctx.site.id
    })
end)

Next: api.forums — discussion boards.

Previous api.users Next api.forums