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

Is it possible render template without $data param? #312

Open
shinriyo opened this issue Feb 4, 2016 · 5 comments
Open

Is it possible render template without $data param? #312

shinriyo opened this issue Feb 4, 2016 · 5 comments

Comments

@shinriyo
Copy link

shinriyo commented Feb 4, 2016

Hi there.

I always watch sample render method with $data
but, I can't find wihtoout $data param.

            return res.render("src/templates/main.tpl");

is best.
but, render method's 2nd param is not optional

So, I always set dummy data....

            let mut data = HashMap::<&str, &str>::new();
            data.insert("dummy", "dymmy");
            return res.render("src/templates/main.tpl", &data);

However it isn't possible return res.render("src/templates/main.tpl", &[[);

@SimonTeixidor
Copy link
Member

If your template does not need any data, then it's just plain HTML, no? If so, just serve that file statically, res.send_file("path/to/main.html"). Or is there some use case for templates without data that I'm not aware of?

@shinriyo
Copy link
Author

shinriyo commented Feb 5, 2016

@simonpersson
Thank you for replying.
yes, I will render just plain HTML. The template doesn't need &data parameters.
I tried your send_file() method. but, It makes downloading main.html file.

I guess I will use the case is home page(like index.tpl).

@Ryman
Copy link
Member

Ryman commented Feb 5, 2016

I tried your send_file() method. but, It makes downloading main.html file.

I think setting the ContentType header to html should fix this? e.g. response.set(MediaType::Html);

@cburgdorf
Copy link
Member

Yep, but it's quite inconvenient. I know I ran into this myself before and we had a discussion on exactly that. Not sure about the right way forward but there should be a simple way to render a template without data, without explicitly setting the MediaType::Html.

@shinriyo
Copy link
Author

shinriyo commented Feb 6, 2016

@Ryman
Thank you for replying.
I resolved it.

@cburgdorf
Did you discussed about it, didn't you?
yes, I hope simple way.
Or, if Rust language and nickel.rs have slogan, TOOWTD, I give up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants