-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Thank you for this very nice project. I love the simple and low-dependency philosophy.
Somewhat not in that vein: what would you think about supporting iteration over maps/objects? Currently iteration is restricted to arrays. Following the standard syntax in other templating languages, it could look something like this:
{{ for key, value in guests }}
The key is {key} and the value is {value}
{{ endfor }}
I poked around the code to see what the implementation would be like, and I think it would be straightforward (I would do it):
-
We would add a new instruction similar to
PushIterationContext. PerhapsPushObjectIterationContext(Path<'template>, &'template str, &'template str)where the enum payload is (path to the map, key variable name, value variable name). -
In the compiler, the
parse_forfunction would be changed to split the key name on,, and then construct either a array iteration spec (no commas), an object iteration spec (1 comma) or an error (2 or more commas). -
The new instruction would have to be implemented in
template.rs. This would follow array iteration, probably with a newContextElement.