Handelbars Helper 未定义

问题描述 投票:0回答:0

我正在使用 Rust 和 Rocket Framework(v0.5) 编写一个网站。我正在使用 Handlebars 并在打开我的网站时收到此错误:

   >> Matched: (index) GET /
   >> Handlebars: Error rendering "index" line 9, col 1: Helper not defined: Path(Relative(([Named("parent")], "parent")))
   >> Template 'index' failed to render.
   >> Outcome: Failure
   >> No 500 catcher registered. Using Rocket default.
   >> Response succeeded.

这是我正在使用的 Rust 代码:

#[macro_use]
extern crate rocket;

use rocket::Request;
use rocket_dyn_templates::Template;

#[derive(serde::Serialize)]
struct BoardContext {
    parent: &'static str,
}

#[derive(serde::Serialize)]
struct AboutContext {
    parent: &'static str,
}

#[derive(serde::Serialize)]
struct LegalsContext {
    parent: &'static str,
}

#[derive(serde::Serialize)]
struct NotFoundContext {
    parent: &'static str,
    url: String,
}

#[get("/")]
fn index() -> Template {
    Template::render("index", &BoardContext { parent: "layout" })
}

#[get("/about")]
fn about() -> Template {
    Template::render("about", &AboutContext { parent: "layout" })
}

#[get("/legals")]
fn legals() -> Template {
    Template::render("legals", &AboutContext { parent: "layout" })
}

#[catch(404)]
fn not_found(req: &Request) -> Template {
    Template::render(
        "not_found",
        NotFoundContext {
            parent: "layout",
            url: req.uri().to_string(),
        },
    )
}

#[launch]
fn rocket() -> _ {
    rocket::build()
        .register("/", catchers![not_found])
        .mount("/", routes![index, about, legals])
        .attach(Template::fairing())
}

这是layout.html.hbs文件:

{{#*inline "page"}}

<section id="message_board">
  <h1>Hi, there!</h1>
    Welcome to my meaningless Website!
</section>

{{/inline}}
{{~> (parent)~}}

这是我的 layout.html.hbs 文件:

<!doctype html>
<html>
  <head>
    <title>website</title>
  </head>
  <body>
    {{> header}}
    {{~> page}}
    {{> footer}}
  </body>
</html>

我尝试添加一个 Handlebars 助手(就像在 Rocket 的示例中一样),但这并没有解决问题。

rust handlebars.js rocket
© www.soinside.com 2019 - 2024. All rights reserved.