{"id":13440047,"url":"https://github.com/sunng87/handlebars-rust","last_synced_at":"2025-05-11T14:00:07.053Z","repository":{"id":24882747,"uuid":"28298785","full_name":"sunng87/handlebars-rust","owner":"sunng87","description":"Rust templating with Handlebars","archived":false,"fork":false,"pushed_at":"2025-04-29T02:24:19.000Z","size":11365,"stargazers_count":1373,"open_issues_count":42,"forks_count":147,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-05-11T14:00:00.255Z","etag":null,"topics":["handlebars","handlebars-js","rust","template-engine"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sunng87.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["sunng87"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"Sunng","issuehunt":null,"otechie":null}},"created_at":"2014-12-21T12:23:33.000Z","updated_at":"2025-05-11T04:11:55.000Z","dependencies_parsed_at":"2024-01-16T18:04:37.910Z","dependency_job_id":"ed6066ba-6c72-4a8d-a775-7b09db4b7298","html_url":"https://github.com/sunng87/handlebars-rust","commit_stats":{"total_commits":1721,"total_committers":85,"mean_commits":20.24705882352941,"dds":0.4997094712376525,"last_synced_commit":"c3d55241886d2e935508ae8e5f17aa689577dc67"},"previous_names":[],"tags_count":143,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fhandlebars-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fhandlebars-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fhandlebars-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fhandlebars-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunng87","download_url":"https://codeload.github.com/sunng87/handlebars-rust/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253576264,"owners_count":21930169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["handlebars","handlebars-js","rust","template-engine"],"created_at":"2024-07-31T03:01:19.311Z","updated_at":"2025-05-11T14:00:07.029Z","avatar_url":"https://github.com/sunng87.png","language":"Rust","readme":"handlebars-rust\n===============\n\n[Handlebars templating language](https://handlebarsjs.com) implemented\nin Rust and for Rust.\n\n[![CI](https://github.com/sunng87/handlebars-rust/actions/workflows/main.yml/badge.svg)](https://github.com/sunng87/handlebars-rust/actions/workflows/main.yml)\n[![Coverage Status](https://coveralls.io/repos/github/sunng87/handlebars-rust/badge.svg?branch=master)](https://coveralls.io/github/sunng87/handlebars-rust?branch=master)\n[![](https://img.shields.io/crates/v/handlebars)](https://crates.io/crates/handlebars)\n[![](https://img.shields.io/crates/d/handlebars.svg)](https://crates.io/crates/handlebars)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n[![Docs](https://docs.rs/handlebars/badge.svg)](https://docs.rs/crate/handlebars/)\n[![Donate](https://img.shields.io/badge/donate-liberapay-yellow.svg)](https://liberapay.com/Sunng/donate)\n\n## Getting Started\n\n### Quick Start\n\n```rust\nuse handlebars::Handlebars;\nuse serde_json::json;\nuse std::error::Error;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn Error\u003e\u003e {\n    let mut reg = Handlebars::new();\n    // render without register\n    println!(\n        \"{}\",\n        reg.render_template(\"Hello {{name}}\", \u0026json!({\"name\": \"foo\"}))?\n    );\n\n    // register template using given name\n    reg.register_template_string(\"tpl_1\", \"Good afternoon, {{name}}\")?;\n    println!(\"{}\", reg.render(\"tpl_1\", \u0026json!({\"name\": \"foo\"}))?);\n\n    Ok(())\n}\n```\n\n### Code Example\n\nIf you are not familiar with [handlebars language\nsyntax](https://handlebarsjs.com), it is recommended to walk through\ntheir introduction first.\n\nExamples are provided in source tree to demo usage of various api.\n\n* [quick](https://github.com/sunng87/handlebars-rust/blob/master/examples/quick.rs)\n  the very basic example of registry and render apis\n* [render](https://github.com/sunng87/handlebars-rust/blob/master/examples/render.rs)\n  how to define custom helpers with function, trait impl or macro, and also how\n  to use custom helpers.\n* [render_file](https://github.com/sunng87/handlebars-rust/blob/master/examples/render_file.rs)\n  similar to render, but render to file instead of string\n* [helper_macro](https://github.com/sunng87/handlebars-rust/blob/master/examples/helper_macro.rs)\n  demos usage of `handlebars_helper!` to simplify helper development\n* [partials](https://github.com/sunng87/handlebars-rust/blob/master/examples/partials.rs)\n  template inheritance with handlebars\n* [decorator](https://github.com/sunng87/handlebars-rust/blob/master/examples/decorator.rs)\n  how to use decorator to change data or define custom helper\n* [script](https://github.com/sunng87/handlebars-rust/blob/master/examples/script.rs)\n  how to define custom helper with rhai scripting language,\n  just like using javascript for handlebarsjs\n* [error](https://github.com/sunng87/handlebars-rust/blob/master/examples/error.rs)\n  simple case for error\n* [dev_mode](https://github.com/sunng87/handlebars-rust/blob/master/examples/dev_mode.rs)\n  a web server hosts handlebars in `dev_mode`, you can edit the template and see the change\n  without restarting your server.\n\n### Web Playground\n\nWe have github action to compile latest `master` branch into WebAssembly and\nserve it on [github pages](https://sunng87.github.io/handlebars-rust/). You can\ntest and verify your template with both handlebars-rust and handlebarjs.\n\n## Minimum Rust Version Policy\n\nHandlebars will track Rust nightly and stable channel. When dropping\nsupport for previous stable versions, I will bump **patch** version\nand clarify in CHANGELOG.\n\n## Docs\n\n[Rust doc](https://docs.rs/crate/handlebars/).\n\n## Changelog\n\nChangelog is available in the source tree named as `CHANGELOG.md`.\n\n## Contributor Guide\n\nAny contribution to this library is welcomed. To get started into\ndevelopment, I have several [Help\nWanted](https://github.com/sunng87/handlebars-rust/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)\nissues, with the difficulty level labeled. When running into any problem,\nfeel free to contact me on github.\n\nI'm always looking for maintainers to work together on this library,\nlet me know (via email or anywhere in the issue tracker) if you\nwant to join.\n\n## Why (this) Handlebars?\n\nHandlebars is a real-world templating system that you can use to build\nyour application without pain.\n\n### Features\n\n#### Isolation of Rust and HTML\n\nThis library doesn't attempt to use some macro magic to allow you to\nwrite your template within your rust code. I admit that it's fun to do\nthat but it doesn't fit real-world use cases.\n\n#### Limited but essential control structures built-in\n\nOnly essential control directives `if` and `each` are built-in. This\nprevents you from putting too much application logic into your template.\n\n#### Extensible helper system\n\nYou can write your own helper with Rust! It can be a block helper or\ninline helper. Put your logic into the helper and don't repeat\nyourself.\n\nA helper can be as a simple as a Rust function like:\n\n```rust\nhandlebars_helper!(hex: |v: i64| format!(\"0x{:x}\", v));\n\n/// register the helper\nhandlebars.register_helper(\"hex\", Box::new(hex));\n```\n\nAnd using it in your template:\n\n```handlebars\n{{hex 16}}\n```\n\nBy default, handlebars-rust ships [additional helpers](https://github.com/sunng87/handlebars-rust/blob/master/src/helpers/helper_extras.rs#L6)\n(compared with original js version)\nthat is useful when working with `if`.\n\nWith `script_helper` feature flag enabled, you can also create helpers\nusing [rhai](https://github.com/jonathandturner/rhai) script, just like JavaScript\nfor handlebars-js. This feature was in early stage. Its API was limited at the\nmoment, and can change in future.\n\n#### Template inheritance\n\nEvery time I look into a templating system, I will investigate its\nsupport for [template\ninheritance](https://docs.djangoproject.com/en/3.2/ref/templates/language/#template-inheritance).\n\nTemplate include is not sufficient for template reuse. In most cases\nyou will need a skeleton of page as parent (header, footer, etc.), and\nembed your page into this parent.\n\nYou can find a real example of template inheritance in\n`examples/partials.rs` and templates used by this file.\n\n#### Auto-reload in dev mode\n\nBy turning on `dev_mode`, handlebars auto reloads any template and scripts that\nloaded from files or directory. This can be handy for template development.\n\n#### WebAssembly compatible\n\nHandlebars 3.0 can be used in WebAssembly projects.\n\n#### Fully scriptable\n\nWith [rhai](https://github.com/rhaiscript/rhai) script support, you\ncan implement your own helper with the scripting language. Together\nwith the template lanaguage itself, template development can be fully\nscriptable without changing rust code.\n\n## Related Projects\n\n### Web frameworks\n\n* Iron: [handlebars-iron](https://github.com/sunng87/handlebars-iron)\n* Rocket: [rocket/contrib](https://api.rocket.rs/v0.4/rocket_contrib/templates/index.html)\n* Warp: [handlebars\n  example](https://github.com/seanmonstar/warp/blob/master/examples/handlebars_template.rs)\n* Tower-web: [Built-in](https://github.com/carllerche/tower-web)\n* Actix: [handlebars\n  example](https://github.com/actix/examples/blob/master/templating/handlebars/src/main.rs)\n* Tide: [tide-handlebars](https://github.com/No9/tide-handlebars)\n* Axum: [axum-template](https://github.com/Altair-Bueno/axum-template)\n\n### Adopters\n\nThe\n[adopters](https://github.com/sunng87/handlebars-rust/wiki/Adopters)\npage lists projects that uses handlebars for part of their\nfunctionalities.\n\n### Extensions\n\nThe\n[extensions](https://github.com/sunng87/handlebars-rust/wiki/Extensions)\npage has libraries that provide additional helpers, decorators and\noutputs to handlebars-rust, and you can use in your own projects.\n\n## License\n\nThis library (handlebars-rust) is open sourced under the MIT License.\n","funding_links":["https://github.com/sponsors/sunng87","https://liberapay.com/Sunng","https://liberapay.com/Sunng/donate"],"categories":["Libraries","Rust","库 Libraries","库","Projects"],"sub_categories":["Web programming","Template engine","网络编程 Web programming","网页编程","模板引擎 Template engine"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunng87%2Fhandlebars-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunng87%2Fhandlebars-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunng87%2Fhandlebars-rust/lists"}