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

Add 'Environment::render_named_str()' #149

Merged
merged 2 commits into from Nov 19, 2022

Conversation

SergioBenitez
Copy link
Contributor

An alternative to 'Environment::render_str()' which allows specifying the rendered template's name.

An alternative to 'Environment::render_str()' which allows specifying the
rendered template's name.
/// let rv = env.render_str_named("Hello {{ name }}", "template", context! { name => "World" });
/// println!("{}", rv.unwrap());
/// ```
pub fn render_str_named<S: Serialize>(
Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

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.

Copy link
Contributor Author

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)?

Copy link
Owner

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)

@mitsuhiko mitsuhiko merged commit b156cdf into mitsuhiko:main Nov 19, 2022
mitsuhiko added a commit that referenced this pull request Nov 19, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants