-
-
Notifications
You must be signed in to change notification settings - Fork 113
Add 'Environment::render_named_str()' #149
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
Conversation
An alternative to 'Environment::render_str()' which allows specifying the rendered template's name.
minijinja/src/environment.rs
Outdated
/// let rv = env.render_str_named("Hello {{ name }}", "template", context! { name => "World" }); | ||
/// println!("{}", rv.unwrap()); | ||
/// ``` | ||
pub fn render_str_named<S: Serialize>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the template name shouldn't go first. That aligns with add_template
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I teeter-tottered between the two options. The reason I chose this was because the method is named render_str_named
, so I wanted to have the str
and then the name
. But it could easily be argued that after "named" should come the name: render_str_named("foo", "{{ the template }}")
. Or maybe the method should be named render_named_str
. I don't have any preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe render_named_str
is a better name anyways. Would probably pick that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
render_named_str(name, template, ctxt)
or render_named_str(template, name, ctxt)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
render_named_str(name, template, ctxt)
analog to add_template(name, template)?.render(ctxt)
An alternative to 'Environment::render_str()' which allows specifying the rendered template's name.