Skip to content
Verified

HTML authoring in Slim

Write regular HTML, add Xuda directives, and let Slim turn it into a program tree.

HTML authoring is the most direct way to learn Slim. Instead of a compiler, you write ordinary HTML and add Xuda directives that bind fields, compute output, toggle visibility, run actions, or iterate over data.

Mental model

  • normal HTML for structure
  • datasource fields for state
  • @field_name expressions for reads
  • Xuda directives for wiring behavior
html
<div xu-store="{'headline':'Hello Xuda'}">
  <input xu-bind="headline" />
  <h1 xu-exp:xu-content="@headline"></h1>
</div>

A full page

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <script src="https://xuda.ai/dist/runtime/js/xuda-runtime-slim.js"></script>
  <script>
    document.addEventListener('DOMContentLoaded', () => {
      document.body.addEventListener('on_mounted', () => {
        console.log('HTML Slim page mounted');
      }, { once: true });

      const Xuda = globalThis.xuda?.xuda || globalThis.xuda;
      new Xuda(document.getElementById('app'), { domain: 'xuda.ai', prog_id: 'demo' });
    }, { once: true });
  </script>
</head>
<body>
  <div id="app"></div>

  <template id="demo">
    <div class="p-6" xu-store="{'title':'Hello from Slim HTML'}">
      <h1 xu-exp:xu-content="@title"></h1>
    </div>
  </template>
</body>
</html>

How <template> becomes a program

When the page contains <template> tags, Slim reads every one of them, uses the template's id attribute as the program id (or template_<index> when there is no id), parses the markup into progUi, and stores the result under _session.project_data.programs. With no prog_id supplied, the first template on the page becomes the startup program.

Templates are optional. If you already pass project_data, templates extend that data rather than replacing it.

Common HTML directives

The full directive reference, including expressions and events, is on Runtime directives.

Attribute value parsing

Template attributes that look like JSON, an array ([...]), an object ({...}) or a quoted JSON string, are parsed with JSON.parse. A valid one becomes a real object or array in progUi; an invalid one stays a plain string. xu-store is the exception: its handler parses with JSON5, so JSON5-style syntax (unquoted keys, single quotes) still works there.

When HTML authoring is the better fit

Use it for docs pages, microsites, product landing pages, embedded widgets and hand-authored prototypes. Move to the CLI once the app grows into multiple routed features, persistence logic needs a clearer home, or several unit types such as get_data, set_data and batch should live outside the page.