{"id":13637079,"url":"https://github.com/sunng87/handlebars-iron","last_synced_at":"2025-04-05T20:09:05.572Z","repository":{"id":25436163,"uuid":"28865900","full_name":"sunng87/handlebars-iron","owner":"sunng87","description":"Handlebars middleware for Iron web framework","archived":false,"fork":false,"pushed_at":"2020-01-26T02:33:58.000Z","size":1042,"stargazers_count":118,"open_issues_count":3,"forks_count":20,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-29T19:07:51.517Z","etag":null,"topics":["handlebars","iron","rust","template-engine","webdevelopment"],"latest_commit_sha":null,"homepage":null,"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":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-06T14:00:17.000Z","updated_at":"2024-12-17T11:16:11.000Z","dependencies_parsed_at":"2022-07-26T07:02:05.248Z","dependency_job_id":null,"html_url":"https://github.com/sunng87/handlebars-iron","commit_stats":null,"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fhandlebars-iron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fhandlebars-iron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fhandlebars-iron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fhandlebars-iron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunng87","download_url":"https://codeload.github.com/sunng87/handlebars-iron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393572,"owners_count":20931813,"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","iron","rust","template-engine","webdevelopment"],"created_at":"2024-08-02T00:01:10.211Z","updated_at":"2025-04-05T20:09:05.545Z","avatar_url":"https://github.com/sunng87.png","language":"Rust","funding_links":[],"categories":["Libraries"],"sub_categories":["Web programming"],"readme":"handlebars-iron\n===============\n\n[Handlebars](https://github.com/sunng87/handlebars-rust) middleware\nfor the [Iron web framework](http://ironframework.io).\n\n[![Build\nStatus](https://travis-ci.org/sunng87/handlebars-iron.svg?branch=master)](https://travis-ci.org/sunng87/handlebars-iron)\n[![](http://meritbadge.herokuapp.com/handlebars-iron)](https://crates.io/crates/handlebars-iron)\n\nThis library, together with handlebars, iron and hyper, works on\nboth stable and nightly rust.\n\nBoth iron and handlebars has backward-incompatible change during 0.x\nreleases. So you will need to choose handlebars-iron version based on\nthose two versions you were using:\n\nhandlebars-iron | handlebars | iron\n--------------- | ---------- | ---\n0.14.x | 0.16.x | 0.2.x\n0.15.x | 0.18.x | 0.3.x\n0.16.0 | 0.19.x | 0.3.x\n0.17.x | 0.19.x | 0.4.x\n0.18.x | 0.20.x (serde 0.8) | 0.4.x\n0.19.x | 0.22.x | 0.4.x\n0.20.x | 0.23.x | 0.4.x\n0.21.x | 0.24.x | 0.4.x\n0.22.x | 0.24.x | 0.5.x\n0.23.x | 0.25.x (serde 0.9) | 0.5.x\n0.24.x | 0.26.x (serde 1.0) | 0.5.x\n0.25.x | 0.29.x | 0.5.x\n0.26.x | 0.32.x | 0.6.x\n0.27.x | 1.x | 0.6.x\n0.28.x | 2.x | 0.6.x\n0.29.x | 3.x | 0.6.x\n\n## Usage\n\nAdd HandlebarsEngine to your Iron middleware chain as an \"after\"\nmiddleware.\n\n```rust\n  /// HandlebarsEngine will look up all files with \"./examples/templates/**/*.hbs\"\n  let mut hbse = HandlebarsEngine::new();\n  hbse.add(Box::new(DirectorySource::new(\"./examples/templates/\", \".hbs\")));\n\n  // load templates from all registered sources\n  if let Err(r) = hbse.reload() {\n    panic!(\"{}\", r);\n  }\n\n  chain.link_after(hbse);\n```\n\nIf you want register your own custom helpers, you can initialize the\n`HandlebarsEngine` from a custom `Handlebars` registry.\n\n```rust\n  let mut hbse = HandlebarsEngine::new();\n  hbse.add(Box::new(DirectorySource::new(\"./examples/templates/\", \".hbs\")));\n  hbse.handlebars_mut().register_helper(\"helper\", my_helper);\n\n  // load templates from all registered sources\n  if let Err(r) = hbse.reload() {\n    panic!(\"{}\", r);\n  }\n\n  chain.link_after(hbse);\n```\n\nYou can find more information about custom helper in [handlebars-rust\ndocument](https://github.com/sunng87/handlebars-rust#extensible-helper-system).\n\nIn your handler, set `Template` to response. As required by\nHandlebars-rust, your data should impl `serde::Serialize`.\n\nFor `DirectorySource`, handlebars engine will walk the directory\nspecified by `prefix`, try to register all templates matches the\nsuffix, and extract its name as template name. For instance,\n`./examples/templates/some/path/index.hbs` will be registered as\n`some/path/index`.\n\n```rust\n/// render data with \"index\" template\n/// that is \"./examples/templates/index.hbs\"\nfn hello_world(_: \u0026mut Request) -\u003e IronResult\u003cResponse\u003e {\n    let mut resp = Response::new();\n\n    let data = ...\n    resp.set_mut(Template::new(\"index\", data)).set_mut(status::Ok);\n    Ok(resp)\n}\n```\n\nBy using `Template::with` You can also render some template without\nactually register it. But this is not recommended because template\nstring needs to be parsed every time. Consider using a `MemorySource`\nif possible.\n\n```rust\n/// render data with \"index\" template\n/// that is \"./examples/templates/index.hbs\"\nfn hello_world(_: \u0026mut Request) -\u003e IronResult\u003cResponse\u003e {\n    let mut resp = Response::new();\n\n    let data = ...\n    resp.set_mut(Template::with(\"\u003ch1\u003e{{title}}\u003c/h1\u003e\", data)).set_mut(status::Ok);\n    Ok(resp)\n}\n```\n\nSince this is simple library, you may run this\n[example](https://github.com/sunng87/handlebars-iron/blob/master/examples/server.rs)\nwith `RUST_LOG=handlebars_iron=info cargo run --example server`\nfirst, and\n[documentation](https://docs.rs/crate/handlebars-iron)\nthen.\n\nRust and its ecosystem are still in early stage, this\nproject might been broken for various reasons. I will try my best to\nkeep this library compiles with latest Rust nightly before the 1.0\nfinal release. If you find anything bad, pull requests and issue reporting\nare always welcomed.\n\n## Live reload\n\nDuring development you may want to live-reload your templates without\nhaving to restart your web server. Here comes the live-reload\nfeature.\n\nSince live-reload may only be useful in development phase, we have\nmade it a optional feature. In order to enable it, you will need to\nadd feature `watch` in your cargo declaration:\n\n```toml\n[features]\n## create a feature in your app\nwatch = [\"handlebars-iron/watch\"]\n\n[dependencies]\nhandlebars-iron = ...\n```\n\nCheck `examples/watch_server.rs` for further information. To test it:\n`RUST_LOG=handlebars_iron=info cargo run --example watch_server\n--features watch`.\n\n## Using handlebars-iron?\n\nAdd your project to our\n[adopters](https://github.com/sunng87/handlebars-rust/wiki/adopters).\n\n## License\n\nMIT, of course.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunng87%2Fhandlebars-iron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunng87%2Fhandlebars-iron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunng87%2Fhandlebars-iron/lists"}