Comments (5)
So include
now works, but only with a string literal path. Not sure that satisfies your use case here?
At some point I think I will need something like a Renderable
trait anyway, also for escaping strings by default (#23). Not yet sure I like this name, but also haven't come up with a better one...
from askama.
Thanks. This does look pretty reasonable while remaining true to being Jinja-like, though you're correct it doesn't quite satisfy my usecase.
For my usecase, I've stuck to just adding a String
field on a template and pre-rendering the partial nested template when intializing the main template. It works well enough, though I still think it'd be cleaner if I could use the actual template type or Box<Template>
or maybe a generic T: Template
(so that i can' hold different nested templates) as the type of a field on another template.
Anyhow, huge thanks for the various fixes/features to improve my use cases. Askama is definitely great to work with!
from askama.
I told you I wasn't done. 😉
I just pushed cece25b, which implements Display
for all Template
s. I experimented with making a separate trait for this which I called Render
(to invoke a similarity to the Read
and Write
traits in std
), but it ends up being identical to Template
, which is not helpful. On top of that, the Template
trait itself is already really similar to Display
, in that the meat of it is just a method that writes stuff into a Write
.
So doing it this way seems to be more ergonomical, and makes conceptual sense: if you derive Template
for your type, it makes sense to me that displaying that type invokes the template implementation. If people want a different serialization, they can use Debug
still, and I could potentially add an option to the template()
attribute to disable generation the impl Display
code.
So, with that, I think you have a nice solution to your problem!
Thanks again for all the feedback, I think it's already made Askama a lot better already, and it has allowed me to more critically review my code from 6 months ago. 👍
from askama.
Huge thanks! Implementing Display
for all Template
s works for me and I mostly agree with your reasoning. I sorta imagine somebody eventually coming along and not wanting that behavior, but I had a hard time thinking up a compelling scenario for that, so 👍 from me.
p.s. I included a shout-out for Askama in this r/rust thread. ;-)
from askama.
Thaks for the shout out, very nice.
from askama.
Related Issues (20)
- Nested comments causes parser to timeout HOT 2
- Publish all crate versions books HOT 7
- if let chain has a weird behaviour HOT 2
- `include` is not very efficient HOT 3
- 0.13.0 release planning HOT 2
- Add tests for generated code HOT 2
- When using askama_axum, the automatic import of IntoResponse will preferentially import from askama_axum instead of axum::response. HOT 4
- Deny all / more reserved keywords as macro names
- Using block fragments as part of larger template HOT 4
- Unnecessary fields required when using blocks for partial rendering HOT 3
- Add `elif` keyword HOT 2
- Template Rendering of a Result<T + Display, E + Display> Cleanly HOT 3
- Feature/docs request: allow setting escape="none" in askama.toml HOT 2
- Include statement has no effect when used from a block fragment HOT 7
- Feedback for me HOT 3
- Add support for remaining pattern syntax (..) in templates
- Unable to publish package containing askama HOT 1
- rendering nested block broken by if-else-endif in outer block HOT 8
- Conditional compiling - features HOT 1
- Children like support for macros / included templates
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from askama.