beginner web-app

Returning HTML Pages

Returning plain text is a start, but web apps need HTML. Clean Language's html: block lets you write HTML directly inside a function — variables are interpolated automatically and the result is just a string you can return.

Part of: Frame framework

The html: block turns indented markup into a returned string:

functions:
	string page_shell(string title, string body_content)
		html:
			<!DOCTYPE html>
			<html lang="en">
			<head>
				<meta charset="UTF-8">
				<title>{title}</title>
				<link rel="stylesheet" href="/css/main.css">
			</head>
			<body>
				{!body_content}
			</body>
			</html>

Variables in curly braces are interpolated. Use {title} for text that should be HTML-escaped — safe for user input. Use {!body_content} when the variable already contains trusted HTML that should not be double-escaped.

Call the helper in your endpoint to build a complete page:

endpoints server:
	GET "/" :
		string content = "<h1>Welcome!</h1><p>Built with Clean Language.</p>"
		string page = page_shell("Welcome", content)
		return http.respond(200, "text/html", page)

	GET "/about" :
		string content = "<h1>About</h1><p>A Clean Language web app.</p>"
		string page = page_shell("About", content)
		return http.respond(200, "text/html", page)
GET /       → 200, full HTML page with title and content
GET /about  → 200, full HTML page with about content

Both routes share the same page_shell helper — change the header or footer once and every page updates. This is Clean Language's component model: reusable string functions.

  • html: block returns a string of HTML — it is syntactic sugar, not a special type
  • Curly-brace interpolation auto-escapes HTML — safe for user-supplied values
  • Curly-brace-! interpolation inserts raw HTML — use only for content you control
  • Build helpers in a functions: block and share them across endpoints
📚 → Book 1, Chapter 2 : Route Parameters →
Copied!