Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rocket_contrib::handlebar_templates does not register partials w/ Handlebars #122

Closed
kestred opened this issue Jan 9, 2017 · 3 comments
Closed
Labels
accepted An accepted request or suggestion bug Deviation from the specification or expected behavior
Milestone

Comments

@kestred
Copy link

kestred commented Jan 9, 2017

Out of the box, Rocket does not correctly handle handlebars partials.

See an example handlebars template:

{{> common/header }}
<main> ... </main>
{{> common/footer }}

I currently have a work-around where I write a little hacky-boilerplate before I launch rocket:

fn main() {
    let empty = HashMap::<String, String>::with_capacity(0);
    Template::render("common/header", &empty);
    Template::render("common/footer", &empty);

    rocket::ignite().mount("/", routes![...]).launch();
}

This works by re-purposing the render() function to register the partials in the HANDLEBARS static variable.

If you can describe your ideal way of fixing this issue, I'd be happy to implement a fix and open a pull request.

@kestred kestred changed the title rocket_contrib::handlebar_templates should register partials w/ Handlebars rocket_contrib::handlebar_templates does not register partials w/ Handlebars Jan 9, 2017
@SergioBenitez
Copy link
Member

What is the layout/structure of your templates directory?

@kestred
Copy link
Author

kestred commented Jan 10, 2017

It is structured like so:

templates/
|__ common/
|   |__ header.html.hbs
|   \__ footer.html.hbs
|
|__ index.html.hbs
\__ etc.html.hbs

This isn't following any particular pattern, it is just what is convenient at the time;
Is there a specific place that rocket.rs recognizes for partials?

@SergioBenitez SergioBenitez added accepted An accepted request or suggestion bug Deviation from the specification or expected behavior labels Jan 10, 2017
@SergioBenitez
Copy link
Member

Indeed. The Handlebars template engine plugin for Rocket is lazy about loading templates. But this clearly indicates that it must be eager. The proper approach is to scan for all of the templates at initialization and register them with handlebars. This is what the Tera engine does, for instance.

@SergioBenitez SergioBenitez added this to the 0.2.0 milestone Jan 10, 2017
SergioBenitez added a commit that referenced this issue Apr 19, 2017
This commit improves and changes the templating library in the following ways:

  * Templates are now registered/loaded at initialization.
  * No synchronization is required to read templates.
  * All templates are properly loaded (fixes #122).
  * Tera templates are given the proper name: `index`, not `index.html.tera`.
  * Rendering tests added for both templating engines.

There is one breaking change:

  * Tera templates are given the proper name: `index`, not `index.html.tera`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted An accepted request or suggestion bug Deviation from the specification or expected behavior
Projects
None yet
Development

No branches or pull requests

2 participants