英文:
Handelbars Helper not defined
问题
以下是您要翻译的内容:
I am programming a Website using Rust and the Rocket Framework(v0.5). I am using Handlebars and get this error when opening my site:
>> 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.
This is the rust code I am using:
#[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())
}
This is the index.html.hbs file:
{{#*inline "page"}}
<section id="message_board">
<h1>Hi, there!</h1>
Welcome to my meaningless Website!
</section>
{{/inline}}
{{~> (parent)~}}
And this is my layout.html.hbs file:
<!doctype html>
<html>
<head>
<title>website</title>
</head>
<body>
{{> header}}
{{~> page}}
{{> footer}}
</body>
</html>
I tried adding a Handlebars helper(like in the example of Rocket) but that didn't resolve the problem.
英文:
I am programming a Website using Rust and the Rocket Framework(v0.5). I am using Handlebars and get this error when opening my site:
>> 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.
This is the rust code I am using:
#[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())
}
This is the index.html.hbs file:
{{#*inline "page"}}
<section id="message_board">
<h1>Hi, there!</h1>
Welcome to my meaningless Website!
</section>
{{/inline}}
{{~> (parent)~}}
And this is my layout.html.hbs file:
<!doctype html>
<html>
<head>
<title>website</title>
</head>
<body>
{{> header}}
{{~> page}}
{{> footer}}
</body>
</html>
I tried adding a Handlebars helper(like in the example of Rocket) but that didn't resolve the problem.
答案1
得分: 1
从:
{{#*inline "page"}}
<section id="message_board">
<h1>Hi, there!</h1>
Welcome to my meaningless Website!
</section>
{{/inline}}
{{~> (parent)~}}
更改为:
{{#*inline "page"}}
<section id="message_board">
<h1>Hi, there!</h1>
Welcome to my meaningless Website!
</section>
{{/inline}}
{{> layout}}
英文:
Answer
After fiddling a lot around, I found out what the problem was. In the index.html.hbs.
From:
{{#*inline "page"}}
<section id="message_board">
<h1>Hi, there!</h1>
Welcome to my meaningless Website!
</section>
{{/inline}}
{{~> (parent)~}}
Changed to:
{{#*inline "page"}}
<section id="message_board">
<h1>Hi, there!</h1>
Welcome to my meaningless Website!
</section>
{{/inline}}
{{> layout}}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论