{"id":13755902,"url":"https://github.com/isaacvando/rtl","last_synced_at":"2026-03-03T19:04:05.252Z","repository":{"id":229962947,"uuid":"764390042","full_name":"isaacvando/rtl","owner":"isaacvando","description":"A template language for Roc with compile time validation and tag unions","archived":false,"fork":false,"pushed_at":"2025-02-01T05:02:18.000Z","size":183,"stargazers_count":31,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-10-10T23:11:34.536Z","etag":null,"topics":["html","html-template","roc-lang","template-engine"],"latest_commit_sha":null,"homepage":"","language":"Roc","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"upl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/isaacvando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-28T01:35:15.000Z","updated_at":"2025-08-29T08:37:02.000Z","dependencies_parsed_at":"2024-04-30T04:56:57.316Z","dependency_job_id":"35b6d41f-2346-4d16-accf-7fa2449cf9ae","html_url":"https://github.com/isaacvando/rtl","commit_stats":null,"previous_names":["isaacvando/roc-template","isaacvando/rtl"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/isaacvando/rtl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isaacvando%2Frtl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isaacvando%2Frtl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isaacvando%2Frtl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isaacvando%2Frtl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isaacvando","download_url":"https://codeload.github.com/isaacvando/rtl/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isaacvando%2Frtl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30056056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html","html-template","roc-lang","template-engine"],"created_at":"2024-08-03T11:00:32.458Z","updated_at":"2026-03-03T19:04:05.228Z","avatar_url":"https://github.com/isaacvando.png","language":"Roc","funding_links":[],"categories":["Roc","Tools 🛠️"],"sub_categories":[],"readme":"# Roc Template Language (RTL)\n\nA template language for Roc with compile time validation and tag unions. RTL can be used with HTML or any other textual content type.\n\nFirst write a template like `hello.rtl`:\n\n```html\n\u003cp\u003eHello, {{model.name}}!\u003c/p\u003e\n\n\u003cul\u003e\n  {|list number : model.numbers |}\n  \u003cli\u003e{{ Num.to_str(number) }}\u003c/li\u003e\n  {|endlist|}\n\u003c/ul\u003e\n\n{|if model.is_subscribed |}\n\u003ca href=\"/subscription\"\u003eSubscription\u003c/a\u003e\n{|else|}\n\u003ca href=\"/signup\"\u003eSign up\u003c/a\u003e\n{|endif|}\n```\n\nThen run `rtl` in the directory containing `hello.rtl` to generate `Pages.roc`.\n\nNow you can call the generated function\n\n```roc\nPages.hello({\n        name: \"World\",\n        numbers: [1, 2, 3],\n        isSubscribed: Bool.true,\n    })\n```\n\nto generate your HTML!\n\n```html\n\u003cp\u003eHello, World!\u003c/p\u003e\n\n\u003cul\u003e\n  \u003cli\u003e1\u003c/li\u003e\n  \u003cli\u003e2\u003c/li\u003e\n  \u003cli\u003e3\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ca href=\"/subscription\"\u003eSubscription\u003c/a\u003e\n```\n\n## Installation\n\nRight now RTL must be built from source:\n\n```bash\ngit clone https://github.com/isaacvando/rtl.git\ncd rtl\nroc build rtl.roc --optimize\nsudo mv rtl /usr/local/bin\n```\n\nNote that building with `--optimize` may take more than 30s (unoptimized builds are fast).\n\n## How It Works\n\nRunning `rtl` in a directory containing `.rtl` templates generates a file called `Pages.roc` which exposes a roc function for each `.rtl` file. Each function accepts a single argument called `model` which can be any type, but will normally be a record.\n\nRTL supports inserting values, conditionally including content, expanding over lists, and pattern matching with when expressions. These constructs all accept normal Roc expressions so there is no need to learn a different set of primitives.\n\nThe generated file, `Pages.roc`, becomes a normal part of your Roc project, so you get type checking right out of the box, for free.\n\n### Inserting Values\n\nTo interpolate a value into the document, use double curly brackets:\n\n```\n{{ model.first_name }}\n```\n\nThe value between the brackets must be a `Str`, so conversions may be necessary:\n\n```\n{{ Num.to_str(2) }}\n```\n\nHTML in the interpolated string will be escaped to prevent security issues like XSS.\n\n### Lists\n\nGenerate a list of values by specifying a pattern for a list element and the list to be expanded over.\n\n```html\n{|list paragraph : model.paragraphs |}\n\u003cp\u003e{{ paragraph }}\u003c/p\u003e\n{|endlist|}\n```\n\nThe pattern can be any normal Roc pattern so things like this are also valid:\n\n```html\n{|list (x,y) : [(1,2),(3,4)] |}\n\u003cp\u003eX: {{ Num.to_str(x) }}, Y: {{ Num.to_str(y) }}\u003c/p\u003e\n{|endlist|}\n```\n\n### When-Is\n\nUse when is expressions like this:\n\n```\n{|when x |}\n    {|is Ok(y) |} The result was ok!\n    {|is Err(_)|} The result was an error!\n{|endwhen|}\n```\n\n### Conditionals\n\nConditionally include content like this:\n\n```\n{|if model.x \u003c model.y |}\n    Conditional content here\n{|endif|}\n```\n\nOr with an else block:\n\n```\n{|if model.x \u003c model.y |}\n    Conditional content here\n{|else|}\n    Other content\n{|endif|}\n```\n\n### Raw Interpolation\n\nIf it is necessary to insert content without escaping HTML, use triple brackets.\n\n```\n{{{ model.dynamic_html }}}\n```\n\nThis is useful for generating content types other than HTML or combining multiple templates into one final HTML output.\n\n### Imports\n\nYou can import a module into the template like this.\n\n```\n{|import MyModule |}\n```\n\n## Tips\n\n### Hot Reloading\n\nYou can achieve a pretty decent \"hot reloading\" experience with a command like this:\n\n```bash\nfswatch -o . -e \".*\" -i \"\\\\.rtl$\" | xargs -n1 -I{} sh -c 'lsof -ti tcp:8000 | xargs kill -9 \u0026\u0026 rtl \u0026\u0026 roc server.roc \u0026'\n```\n\n### Syntax Highlighting\n\nIf you want to get the syntax highlighting for the ambient content type in all of your `.rtl` files in VS Code, you can create a file association like this in `settings.json`:\n\n```json\n\"files.associations\": {\n  \"*.rtl\": \"html\"\n}\n```\n\n## Talk\n\nI gave a talk about RTL at LambdaConf 2024 called [_Writing a Type-Safe HTML Template Language for Roc_](https://youtu.be/VXQub6U_BUM?si=8rzBNBRZHo0i5X1O) which explains how RTL takes advantages of Roc features like structural typing and type inference.\n\n## Todo\n\n- [ ] Allow more control for whitespace around RTL tags.\n- [ ] Allow RTL tags to be escaped.\n- [ ] Look into real hot code reloading.\n- [ ] Potentially update the generated code to use buffer passing style to avoid unnecessary copies.\n- [ ] Benchmark runtime performance against other template languages.\n- [ ] Potentially add error messages for incomplete tags.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisaacvando%2Frtl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisaacvando%2Frtl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisaacvando%2Frtl/lists"}