Liquid for loop with if conditions



examples/liquid/liquid-loop-and-if/src/main.rs
fn main() {
    let template = "
       {% for animal in animals %}
            {% if animal.real %}
                A real {{animal.name}}
            {% else %}
                A fake {{animal.name}}
            {% endif %}
        {% endfor %}
    ";

    let template = liquid::ParserBuilder::with_stdlib()
        .build().unwrap()
        .parse(template).unwrap();

    let globals = liquid::object!({
        "animals": [
            {
                "name": "mouse",
                "real": true,
            },
            {
                "name": "snake",
                "real": true,
            },
            {
                "name": "oliphant",
                "real": false,
            },
        ],
    });
    let output = template.render(&globals).unwrap();
    println!("{}", output);
}

examples/liquid/liquid-loop-and-if/out.txt
       
            
                A real mouse
            
        
            
                A real snake
            
        
            
                A fake oliphant