- Another example passing in a vector, but this time a vector of tuples.
- We use the square-brackets
[] and indexes to access the elements of a tuple.
fn main() {
let template = "
{% for color in colors %}
{{ color[0] }} - {{ color[1] }}
{% endfor %}
";
let template = liquid::ParserBuilder::with_stdlib()
.build()
.unwrap()
.parse(template)
.unwrap();
let colors = vec![("red", 23), ("green", 17), ("blue", 42)];
let globals = liquid::object!({
"colors": colors,
});
let output = template.render(&globals).unwrap();
println!("{}", output);
}
red - 23
green - 17
blue - 42