Skip to content

HTML Templates (.html)

Orbita's recommended way to build UI is clean file separation inspired by Angular and Vue:

  • index.tyl — server logic (load, action, components)
  • index.html — clean HTML template with control flow and bindings
  • index.css (optional) — scoped or page-specific styles automatically injected alongside the template

Every .html template is compiled to Luau and cached in memory automatically (with instant mtime recompilation in --watch mode).


Interpolation

  • {{ expr }} — HTML-escaped output (safe against XSS by default).
  • {{{ expr }}} — raw unescaped HTML (use only for trusted/sanitized HTML).
<h1>{{ post.title }}</h1>
<p>Welcome back, {{ ctx.user.name }}!</p>
<div class="rendered">{{{ raw_html }}}</div>

Control Flow (@if, @for ... @empty)

Inspired by Angular 17+, control flow blocks use standard Luau expressions without awkward wrapper tags:

Conditionals (@if / @else if / @else)

@if (ctx.user and ctx.user.is_admin) {
  <span class="badge admin">Admin</span>
} @else if (ctx.user) {
  <span class="badge">Member</span>
} @else {
  <a href="/auth/login">Sign In</a>
}

Loops (@for ... @empty)

<ul class="task-list">
  @for (task in tasks) {
    <li :class="task.done and 'done' or 'pending'">
      {{ task.title }}
    </li>
  } @empty {
    <li class="empty">No tasks found.</li>
  }
</ul>

Attribute & Event Bindings (Vue-Style)

Dynamic Attributes (:attr)

Prefix any HTML attribute with : to bind a Luau expression:

  • false or nil omits the attribute completely.
  • true renders a boolean attribute (e.g. checked, disabled).
  • Strings and numbers are automatically HTML-escaped.
<input type="checkbox" :checked="task.done" />
<input type="hidden" name="_csrf" :value="csrf_token" />
<a :href="'/posts/' .. post.id" :class="is_active and 'nav active' or 'nav'">
  {{ post.title }}
</a>

Interpolation inside normal attributes also works:

<a href="/posts/{{ post.id }}">{{ post.title }}</a>
<link rel="stylesheet" href="{{ asset('styles.css') }}" />

Event Directives (@click, @submit.prevent)

Event attributes compile to standard data-ob-on-* and data-ob-mod-* attributes for progressive enhancement or client-side scripts:

<form @submit.prevent="saveTask">
  <button type="button" @click="toggleModal">Open</button>
</form>

Layouts & <slot />

Place a _layout.html (and optional _layout.tyl) in any route directory. Child routes automatically render inside <slot />:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>{{ title or "Orbita App" }}</title>
    <link rel="stylesheet" href="{{ asset('styles.css') }}" />
  </head>
  <body>
    <main>
      <slot />
    </main>
    <script src="{{ asset('app.js') }}"></script>
  </body>
</html>

Reusable Components (<Component :prop="val" />)

Generate a component with ob g component <app>/<name>:

src/apps/tasks/components/task_card/task_card.html

<div class="task-card">
  <span>{{ title }}</span>
  @if (done) {
    <span class="badge">Done</span>
  }
</div>

src/apps/tasks/components/task_card/task_card.tyl

local html = require("ob:html")

return function(props)
    return html.template("apps/tasks/components/task_card/task_card.html", props)
end

Register it in your route's components table and use it as a PascalCase tag:

-- routes/index.tyl
local TaskCard = require("../components/task_card/task_card")

return {
    components = { TaskCard = TaskCard },
    load = function(ctx)
        return { tasks = Tasks:all() }
    end,
}
<!-- routes/index.html -->
@for (t in tasks) {
  <TaskCard :title="t.title" :done="t.done == 1" />
}

Built-in Template Helpers

Every .html template automatically receives:

Helper / Variable Description
asset(path) Resolves a static file to a cache-busted URL (e.g. "/public/styles.css?v=9f3a1c2d"). See Caching.
ctx Current request context (ctx.path, ctx.query, ctx.params, ctx.user, etc.).
flash One-shot flash messages set via ctx:flash(kind, msg).
csrf_token Current CSRF token when router.csrf() middleware is active.