Writing JSX Taragen's JSX is a server-side template language. Elements turn straight into HTML strings; there is no React, no components with state, no hooks, and nothing runs in the browser. Write `class`, not `className`. ## Pages, data, and multiple roots A JSX page can have several root elements, or start with an expression: ```jsx data({ title: "Home" });

Welcome

Latest posts:

{partial("_partials/latest")} ``` A `data({...})` call at the very top of the file (after whitespace and comments) sets page data. The trailing `;` is optional. `data()` merges its object into both `page` and the page's data, so later code in the file and the layouts see it. In a [generated page template](/docs/manual/generated-pages), a `params(...)` call can sit alongside `data()` in these leading statements. ## Values in JSX Children can be elements, strings, numbers, or arrays (flattened, so `.map(...)` works). `null`, `undefined`, `true`, and `false` render nothing, so conditionals work: ```jsx {page.draft && Draft} {page.tags?.map(t => {t})} ``` Attribute values can be: | Value | Result | | --- | --- | | string | `name="value"`; an empty string omits the attribute | | number | Printed as JS prints it | | `true` / `false` | Bare attribute (``) / omitted | | object | Serialized as a `style` string: `style={{ color: "red", "font-size": "2em" }}` | | `null` / `undefined` | Omitted | Anything else, such as an object as a child or a function as an attribute, throws a `TypeError` and fails the render. Attributes are written in the order you wrote them, and the output is identical on every build, so diffs of `_public/` show only real changes. Void elements like ``, ``, and `
` are self-closed. ## Escaping and `raw()` Text and attribute values are escaped, so a title with `&` or `"` is safe anywhere, including in attributes and XML feeds. Text inside `