# platelet `platelet` is an HTML-first templating language. This repo contains a Rust library for rendering `platelet` templates. ## Why platelet? Unlike `moustache`, `handlebars`, `Jinja`, `Liquid` and other templating languages, `platelet`'s syntax is part of HTML (similar to Vue.js). This has a few upsides: - **Higher level** but [less powerful](https://www.w3.org/DesignIssues/Principles.html#:~:text=Principle%20of%20Least%20Power) than direct string manipulation - The language is **natural to read and write** when working with HTML, and control flow follows HTML structure - You can use your own HTML formatters and **tooling** - HTML **sanitization** is more natural and straightforward ## Example You can explore live examples in the [platelet playground](https://angusjf.com/platelet/playground) ###### Template ```html ``` ###### Context (input) ```json { "n": 7 } ``` ###### Output ```html ```
More examples ### Advanced example ###### Template `templates/index.html` ```html {{ title }} ``` ###### Template `templates/blogpost.html` ```html

{{blogpost.title}}

{{blogpost.date}}
``` ###### Context (input) ```json { "title": "Angus' Blog", "blogposts": [ { "img_url": "...", "link": "...", "summary": "...", "title": "...", "date": "01/11/2025" }, { "img_url": "...", "link": "...", "summary": "...", "title": "...", "date": "01/11/2020" } ] } ```
## Reference | Syntax | Example | Details | | ----------------- | --------------------- | -------------------- | | `pl-` directives | `pl-if`, `pl-for` ... | [→](#pl--directives) | | `^` attributes | `^class`, `^name` ... | [→](#-attributes) | | `{{ ... }}` nodes | `{{ user.email }}` | [→](#text-nodes) | | Expressions | `1 + users[i].score` | [→](#expressions) | ## `pl-` Directives HTML Attributes starting with a `pl-` are special. They are inspired by Vue's directives. | attribute | | ------------ | | `pl-if` | | `pl-else-if` | | `pl-else` | | `pl-for` | | `pl-html` | | `pl-src` | | `pl-slot` | | `pl-is` | ### Conditionals: `pl-if`, `pl-else-if`, `pl-else` `pl-if` will only render this element if the expression is truthy `pl-else-if`, used following a `pl-if`, will only render this element if the expression is truthy `pl-else`, used following a `pl-if` or `pl-else-if`, will render this element otherwise ```html ``` If applied to a `