global variables
HosMercury opened this issue · comments
hi thx for the crate effort
i have a situation that i got a hashed variables js and css names from vite build
these names should be included in the base.html head tag
the solutions i got from searching are not convenient for me.
i have read this https://djc.github.io/askama/template_syntax.html
also it’s not convenient to share the same data again and again with each call to a template like here #535
it is the same data but changing only when i build with vite like style-ghsed4.css and script-o0k8jkl.js . i got them then i have a function to inject them but no way to call it from the template .
shared data ( global locals vars ) concept is missing from the crate afaik.
static global var => is difficult to deal with because it needs const funcs
If not a Rust static
, it's not really obvious to me what you're looking for. Maybe provide a concrete example?
fn manifest(env: &String) {
let mut entries = fs::read_dir("./public/assets")
.unwrap()
.map(|res| res.map(|e| e.path()))
.collect::<Result<Vec<_>, io::Error>>()
.unwrap();
println!("{:?}", entries);
}
see I want to add the CSS file I got from entries to the index.html head..
using fs with const funcs is not allowed
Well, I don't think that makes sense. You might be able to use something like a once_cell::sync::Lazy
to have a static
that contains what you need.
yes it helps thx