-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
Question: passing a const, not as a field. #291
Comments
As a workaround, try referencing it through a path, for example, from the crate root? Askama tries not to use its knowledge of the context fields, and instead keeps track of local variables, such that everything non-local is treated as a context field. Maybe this can be improved, although I think there were some benefits to the current state. Alternatively, since we know that all-uppercase names are never fields, we could probably hack our way around this. Would you be able to take a swing at this? It would be as simple as modifying the function here: https://github.com/djc/askama/blob/master/askama_derive/src/generator.rs#L1137 to stop it from prepending |
I can certainly try. It doesn't seem like a particularly complex change, with the exact function being pointed out. I'm gonna be busy for a few days, though. For now I'll just use the workaround. Thanks! |
I'm trying to reference a constant in my template, since I reuse it all over the place (including across templates) and it'd be a pain to have to update it everywhere it needs to change. I have a template file with
{{ date.format(FMT_STR) }}
, aconst FMT_STR: &'static str = "...";
, and adate: chrono::naive::NaiveDate
. As expected, this producesself.date.format(self.FMT_STR)
. How can I getself.date.format(FMT_STR)
instead? i.e. How can I refer to my constant, instead of a field?The text was updated successfully, but these errors were encountered: