Liquid comma between every two elements (forloop.last)
- length
- index (numbers start from 1)
- index0 (numbers start from 0)
- rindex
- rindex0
- first
- last
examples/liquid/liquid-loop-last/src/main.rs
fn main() { let result = render("direct: {% for item in items %}{{item}}, {% endfor %}"); println!("{}", result); } fn render(tmpl: &str) -> String { let template = liquid::ParserBuilder::with_stdlib() .build() .unwrap() .parse(tmpl) .unwrap(); let globals = liquid::object!({ "items": vec![2, 3, 4, 5, 6, 7, 8], }); template.render(&globals).unwrap() } #[test] pub fn test_reverse() { let result = render("direct: {% for item in items %}{{item}}, {% endfor %}"); assert_eq!(result, "direct: 2, 3, 4, 5, 6, 7, 8, "); let result = render("direct: {% for item in items %}{{item}}{% if forloop.last %}{% else %}, {% endif %}{% endfor %}"); assert_eq!(result, "direct: 2, 3, 4, 5, 6, 7, 8"); }
direct: 2, 3, 4, 5, 6, 7, 8,