Built-in Functions
Wunderframe applications provide a rich set of built-in functions for interacting with content nodes, making HTTP requests, logging, and handling various application tasks. These functions are available in the Lua runtime context.
Content Node Functions
get_node(path: String) -> JSON
Retrieves a node by path without extending/resolving references. Fast for basic node data.
-- Get a content node
local node = get_node("stories/example/page")
print("Node title:", node.properties.title)
print("Content type:", node.content_type)
get_page(path: String) -> JSON
Retrieves a node and extends it by resolving all references and relationships. Use this when you need fully populated node data.
-- Get a fully resolved page with all references
local page = get_page("stories/example/homepage")
-- This includes resolved assets, related content, etc.
get_children(path: String) -> JSON[]
Fetches direct child nodes of a given path without extending them.
-- Get navigation items
local nav = get_children("stories/" .. pageContext.story_node.path .. "/site")
for i, item in ipairs(nav) do
print("Nav item:", item.properties.title or item.name)
end
get_page_children(path: String) -> JSON[]
Fetches and fully extends child nodes, resolving all their references.
-- Get a menu with all child pages fully resolved
local menu_items = get_page_children("stories/site/navigation")
update_node(node: Table) -> Boolean
Updates a node's information in the content repository. The node must include a workspace field.
-- Update node properties
local node = get_node("stories/example")
node.properties.title = "New Title"
node.properties.updated_at = os.date("!%Y-%m-%dT%H:%M:%SZ")
local success = update_node(node)
if success then
log("info", "Node updated successfully")
else
log("error", "Failed to update node")
end
search_nodes(workspace: String, query: Table, status: String) -> JSON[]
Searches for nodes without extending them. Status can be "published" or "draft".
-- Search for published blog posts
local query = {
content_type = "blog:post",
path_pattern = "stories/blog/**"
}
local posts = search_nodes("workspace", query, "published")
search(workspace: String, query: Table, status: String) -> JSON[]
Searches for nodes and extends them with full context and references.
-- Search for pages with full content resolution
local query = { content_type = "page:standard" }
local pages = search("workspace", query, "published")
-- Each page in results will have fully resolved assets, etc.
get_workspace(workspace_name: String) -> LuaNodeRepo
Gets a repository instance for a specific workspace. Advanced usage for direct repository operations.
local repo = get_workspace("my_workspace")
-- Use repo for advanced node operations
Logging Functions
log(level: String, message: String)
Logs a message with a specified log level. Available levels: "info", "warn", "error", "debug".
log("info", "User logged in successfully")
log("warn", "Cache miss for key: " .. cache_key)
log("error", "Failed to process payment: " .. error_message)
log("debug", "Variable state: " .. json.encode(debug_data))
HTTP Functions
http.get(url: String) -> Response
Performs an HTTP GET request and returns a response table with status and body.
local response = http.get("https://api.example.com/users")
if response.status == 200 then
local users = response.body -- Automatically parsed JSON if valid
for i, user in ipairs(users) do
print("User:", user.name)
end
else
log("error", "API request failed with status: " .. response.status)
end
http.post(url: String, body: Any, headers?: Table) -> Response
Performs an HTTP POST request. Body can be a string or table (automatically JSON-encoded).
-- POST with JSON data
local response = http.post(
"https://api.example.com/users",
{ name = "John Doe", email = "john@example.com" },
{ ["Authorization"] = "Bearer " .. api_token }
)
-- POST with string data
local response = http.post(
"https://api.example.com/webhook",
"raw string data",
{ ["Content-Type"] = "text/plain" }
)
if response.status == 201 then
log("info", "User created successfully")
else
log("error", "Failed to create user: " .. response.body)
end
Context Functions
Context functions allow sharing data between components during rendering.
getContext(key: String) -> Any
Retrieves a value from the current render context. Common context keys:
"pageContext"
- Page-level data including URLs, query parameters"currentNode"
- The current content node being rendered"currentTheme"
- Active theme settings
-- Get page context data
local pageContext = getContext("pageContext")
local rootPath = pageContext.root_path
local isDev = pageContext.query.dev
local isPreview = pageContext.query.preview
-- Get current node
local currentNode = getContext("currentNode")
local pageTitle = currentNode.properties.title
local contentType = currentNode.content_type
-- Get theme settings
local currentTheme = pageContext.currentTheme
setContext(key: String, value: Any)
Sets a value in the current render context. Use this in app.lua to provide data to templates.
-- In app.lua
local helpers = createContextHelpers(runtime)
helpers.createContext()
-- Set context for templates to use
helpers.setContext("currentNode", currentNode)
helpers.setContext("pageContext", pageContext)
helpers.setContext("userData", user_data)
createContextHelpers(runtime) -> Helpers
Creates context helper functions. Used in app.lua to set up the rendering context.
-- In app.lua render function
local helpers = createContextHelpers(runtime)
helpers.createContext() -- Initialize context
-- Now you can use helpers.setContext() and getContext() is available in templates
URL Utility Functions
get_relative_parent(path: String, level: Int) -> String
Finds the relative parent path by going up the specified number of levels.
-- Go up 2 levels from current path
local parent_path = get_relative_parent("stories/blog/2024/post1", 2)
-- Returns: "stories/blog"
get_absolute_parent(path: String, level: Int) -> String
Finds the absolute parent path by going up the specified number of levels.
-- Get parent directory with absolute path
local absolute_path = get_absolute_parent("/stories/blog/post1", 1)
-- Returns: "/stories/blog"
JSON Functions
json
module
The json
module is automatically available for encoding and decoding JSON data.
local json = require("json")
-- Encode Lua table to JSON string
local data = { name = "John", age = 30, active = true }
local json_string = json.encode(data)
-- Result: '{"name":"John","age":30,"active":true}'
-- Decode JSON string to Lua table
local parsed = json.decode(json_string)
print(parsed.name) -- "John"
-- Use in templates for client-side data
local user_data = json.encode({
currentNode = currentNode,
permissions = user_permissions
})
-- Then in HTML: <div x-data={user_data}></div>
Built-in Modules
These modules are automatically available without explicit installation:
json
- JSON encoding/decodingmlua_json
- Advanced JSON handling (preloaded)- HTTP client - Available via
http.get()
andhttp.post()
- Logging system - Available via
log()
function
Function Reference Summary
Function | Purpose | Returns |
---|---|---|
get_node(path) | Get basic node data | JSON object |
get_page(path) | Get extended node data | JSON object |
get_children(path) | Get child nodes | JSON array |
get_page_children(path) | Get extended child nodes | JSON array |
search_nodes(ws, query, status) | Search nodes (basic) | JSON array |
search(ws, query, status) | Search nodes (extended) | JSON array |
update_node(node) | Update node data | Boolean |
log(level, message) | Log message | None |
http.get(url) | HTTP GET request | Response object |
http.post(url, body, headers) | HTTP POST request | Response object |
getContext(key) | Get context value | Any |
setContext(key, value) | Set context value | None |
get_relative_parent(path, level) | Get relative parent | String |
get_absolute_parent(path, level) | Get absolute parent | String |
These built-in functions provide everything needed for building robust Wunderframe applications with content management, HTTP communication, logging, and context sharing.