askama icon indicating copy to clipboard operation
askama copied to clipboard

Add ability to get template's filename from DynTemplate

Open wathiede opened this issue 3 years ago • 1 comments

I'd like to iterate over a bunch of DynTemplate objects, saving each rendering to a path derived from the source path. The easiest way that came to mind was adding a path accessor to the DynTemplate, much like was done with extensions. I prototyped a solution base on this idea in this commit.

If this is a reasonable addition I'm happy to send a pull request. One downside is that it returns the full path to the source, which may leak details into the binary (i.e. the building user's name if built under your home directory on a unix-like system). An alternative might be to store the path relative to the templates directory. That seemed complex enough (given you have to deal with search paths in the askama config) that I figured I'd file this issue to discuss.

wathiede avatar Mar 20 '22 21:03 wathiede

Seems reasonable enough. I do think this should return the path relative to the search directory where it was found. Note that the path is not always defined (in the case of #[template(source = "")] templates), so it should probably be an Option.

djc avatar Mar 20 '22 23:03 djc