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.pages & api.codes

`api.pages` and `api.codes` work together — codes are script blocks attached to pages. Pages are the documents, codes are the logic.

On this page

The pages & codes domains

api.pages and api.codes work together — codes are script blocks attached to pages. Pages are the documents, codes are the logic.

api.pages reference

Function Returns Description
api.pages.get(id) table or nil Get a page by ID
api.pages.list(filter?) { items, total } List pages with filters

List filter

api.pages.list({
    type = 0,              -- 0=HTML, 1=Text, 2=CSS, 3=JS, 4=JSON, 5=XML
    search = "about",      -- search page names
    order = "id_asc",      -- sort order
    page = 1,
    limit = 50
})

Reading a page

local page = api.pages.get(10)
if page then
    print(page.name)       -- "about"
    print(page.type)       -- 0 (HTML)
    print(page.content)    -- "<h1>About Us</h1>..."
end

api.codes reference

Function Returns Description
api.codes.get(id) table or nil Get a code block by ID
api.codes.list(pageId) table[] List all codes on a page
api.codes.create(pageId, data) table Create a code entry
api.codes.update(id, data) table Update a code entry
api.codes.delete(id) boolean Delete a code entry
api.codes.copy(codeId, pageId) table Copy code to another page
api.codes.move(codeId, pageId) table Move code to another page
api.codes.up(codeId) boolean Move code up in execution order
api.codes.down(codeId) boolean Move code down in execution order

Creating code on a page

-- Add a TAG macro to a page
local code = api.codes.create(10, {
    content = "{{VAR(site_title)}}",
    type = 2,              -- 2 = TAG
    position = 0
})

Listing codes on a page

local codes = api.codes.list(10)
for _, c in ipairs(codes) do
    print(c.type_label .. " at position " .. c.position)
end

Reordering codes

-- Move a code block up or down in execution order
api.codes.up(code.id)     -- earlier
api.codes.down(code.id)   -- later

Moving code between pages

-- Move a code entry from page 10 to page 20
api.codes.move(code.id, 20)

-- Or copy it (keeps original)
api.codes.copy(code.id, 20)

Code types

Type Label Description
0 Literal Raw code (no processing)
1 HTML HTML markup
2 TAG {{VAR()}} macro tags
3 YouTube API YouTube integration
... ... +26 additional types

Building a page editor

-- List all HTML pages for an admin panel
app:get("/admin/pages", function(ctx)
    local pages = api.pages.list({ type = 0 })

    -- For each page, count its code blocks
    for _, page in ipairs(pages.items) do
        local codes = api.codes.list(page.id)
        page.code_count = #codes
    end

    return ctx:render("admin_pages", { pages = pages.items })
end)

Next: api.dataset — your own database. Store and query anything.

Previous api.files & api.folders Next api.dataset